From fba205f27eae526f27bd4c2b78f3c97c18ebdbfb Mon Sep 17 00:00:00 2001 From: "Owain G. Ainsworth" Date: Wed, 9 Apr 2014 16:09:24 +0100 Subject: [PATCH] Use AccountByAddress() to save iteration. --- acctmgr.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/acctmgr.go b/acctmgr.go index 412cd4f..fe5e184 100644 --- a/acctmgr.go +++ b/acctmgr.go @@ -712,21 +712,11 @@ func (am *AccountManager) DumpKeys() ([]string, error) { // DumpWIFPrivateKey searches through all accounts for the bitcoin // payment address addr and returns the WIF-encdoded private key. func (am *AccountManager) DumpWIFPrivateKey(addr btcutil.Address) (string, error) { - for _, a := range am.AllAccounts() { - switch wif, err := a.DumpWIFPrivateKey(addr); err { - case wallet.ErrAddressNotFound: - // Move on to the next account. - continue - - case nil: - return wif, nil - - default: // all other non-nil errors - return "", err - } + a, err := am.AccountByAddress(addr) + if err != nil { + return "", err } - - return "", errors.New("address does not refer to a key") + return a.DumpWIFPrivateKey(addr) } // NotifyBalances notifies a wallet frontend of all confirmed and unconfirmed