Revert "Can now specify the number of empty accounts to derive"

This reverts commit 5b30aa59d6.
This commit is contained in:
Péter Szilágyi 2019-04-10 12:51:22 +03:00
parent f0b878d56d
commit 8cf764da89
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D

View File

@ -390,7 +390,7 @@ func (w *Wallet) Open(passphrase string) error {
w.deriveReq = make(chan chan struct{}) w.deriveReq = make(chan chan struct{})
w.deriveQuit = make(chan chan error) w.deriveQuit = make(chan chan error)
go w.selfDerive(0) go w.selfDerive()
// Notify anyone listening for wallet events that a new device is accessible // Notify anyone listening for wallet events that a new device is accessible
go w.Hub.updateFeed.Send(accounts.WalletEvent{Wallet: w, Kind: accounts.WalletOpened}) go w.Hub.updateFeed.Send(accounts.WalletEvent{Wallet: w, Kind: accounts.WalletOpened})
@ -426,9 +426,8 @@ func (w *Wallet) Close() error {
} }
// selfDerive is an account derivation loop that upon request attempts to find // selfDerive is an account derivation loop that upon request attempts to find
// new non-zero accounts. maxEmpty specifies the number of empty accounts that // new non-zero accounts.
// should be derived once an initial empty account has been found. func (w *Wallet) selfDerive() {
func (w *Wallet) selfDerive(maxEmpty int) {
w.log.Debug("Smart card wallet self-derivation started") w.log.Debug("Smart card wallet self-derivation started")
defer w.log.Debug("Smart card wallet self-derivation stopped") defer w.log.Debug("Smart card wallet self-derivation stopped")
@ -466,7 +465,7 @@ func (w *Wallet) selfDerive(maxEmpty int) {
context = context.Background() context = context.Background()
) )
for empty, emptyCount := false, maxEmpty+1; !empty || emptyCount > 0; { for empty := false; !empty; {
// Retrieve the next derived Ethereum account // Retrieve the next derived Ethereum account
if nextAddr == (common.Address{}) { if nextAddr == (common.Address{}) {
if nextAcc, err = w.session.derive(nextPath); err != nil { if nextAcc, err = w.session.derive(nextPath); err != nil {
@ -490,11 +489,9 @@ func (w *Wallet) selfDerive(maxEmpty int) {
w.log.Warn("Smartcard wallet nonce retrieval failed", "err", err) w.log.Warn("Smartcard wallet nonce retrieval failed", "err", err)
break break
} }
// If the next account is empty and no more empty accounts are // If the next account is empty, stop self-derivation, but add it nonetheless
// allowed, stop self-derivation. Add the current one nonetheless.
if balance.Sign() == 0 && nonce == 0 { if balance.Sign() == 0 && nonce == 0 {
empty = true empty = true
emptyCount--
} }
// We've just self-derived a new account, start tracking it locally // We've just self-derived a new account, start tracking it locally
path := make(accounts.DerivationPath, len(nextPath)) path := make(accounts.DerivationPath, len(nextPath))
@ -508,7 +505,7 @@ func (w *Wallet) selfDerive(maxEmpty int) {
pairing.Accounts[nextAddr] = path pairing.Accounts[nextAddr] = path
// Fetch the next potential account // Fetch the next potential account
if !empty || emptyCount > 0 { if !empty {
nextAddr = common.Address{} nextAddr = common.Address{}
nextPath[len(nextPath)-1]++ nextPath[len(nextPath)-1]++
} }
@ -592,7 +589,7 @@ func (w *Wallet) Contains(account accounts.Account) bool {
// Initialize installs a keypair generated from the provided key into the wallet. // Initialize installs a keypair generated from the provided key into the wallet.
func (w *Wallet) Initialize(seed []byte) error { func (w *Wallet) Initialize(seed []byte) error {
go w.selfDerive(0) go w.selfDerive()
// DO NOT lock at this stage, as the initialize // DO NOT lock at this stage, as the initialize
// function relies on Status() // function relies on Status()
return w.session.initialize(seed) return w.session.initialize(seed)