Use AccountByAddress() to save iteration.

This commit is contained in:
Owain G. Ainsworth 2014-04-09 16:09:24 +01:00
parent 674e9f2427
commit fba205f27e

View file

@ -712,21 +712,11 @@ func (am *AccountManager) DumpKeys() ([]string, error) {
// DumpWIFPrivateKey searches through all accounts for the bitcoin // DumpWIFPrivateKey searches through all accounts for the bitcoin
// payment address addr and returns the WIF-encdoded private key. // payment address addr and returns the WIF-encdoded private key.
func (am *AccountManager) DumpWIFPrivateKey(addr btcutil.Address) (string, error) { func (am *AccountManager) DumpWIFPrivateKey(addr btcutil.Address) (string, error) {
for _, a := range am.AllAccounts() { a, err := am.AccountByAddress(addr)
switch wif, err := a.DumpWIFPrivateKey(addr); err { if err != nil {
case wallet.ErrAddressNotFound: return "", err
// Move on to the next account.
continue
case nil:
return wif, nil
default: // all other non-nil errors
return "", err
}
} }
return a.DumpWIFPrivateKey(addr)
return "", errors.New("address does not refer to a key")
} }
// NotifyBalances notifies a wallet frontend of all confirmed and unconfirmed // NotifyBalances notifies a wallet frontend of all confirmed and unconfirmed