diff --git a/acctmgr.go b/acctmgr.go index 9e1d73b..0f81399 100644 --- a/acctmgr.go +++ b/acctmgr.go @@ -484,6 +484,17 @@ func (am *AccountManager) MarkAddressForAccount(address btcutil.Address, } } +// Address looks up an address if it is known to wallet at all. +func (am *AccountManager) Address(addr btcutil.Address) (wallet.WalletAddress, + error) { + a, err := am.AccountByAddress(addr) + if err != nil { + return nil, err + } + + return a.Address(addr) +} + // AllAccounts returns a slice of all managed accounts. func (am *AccountManager) AllAccounts() []*Account { respChan := make(chan []*Account) diff --git a/rpcserver.go b/rpcserver.go index 855ad0f..479b1dc 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -286,7 +286,7 @@ func makeMultiSigScript(keys []string, nRequired int) ([]byte, *btcjson.Error) { case *btcutil.AddressPubKey: keysesPrecious[i] = addr case *btcutil.AddressPubKeyHash: - act, err := AcctMgr.AccountByAddress(addr) + ainfo, err := AcctMgr.Address(addr) if err != nil { return nil, &btcjson.Error{ Code: btcjson.ErrParse.Code, @@ -294,13 +294,6 @@ func makeMultiSigScript(keys []string, nRequired int) ([]byte, *btcjson.Error) { } } - ainfo, err := act.Address(addr) - if err != nil { - return nil, &btcjson.Error{ - Code: btcjson.ErrParse.Code, - Message: err.Error(), - } - } apkinfo := ainfo.(wallet.PubKeyAddress) // This will be an addresspubkey @@ -1641,19 +1634,11 @@ func SignMessage(icmd btcjson.Cmd) (interface{}, *btcjson.Error) { } } - a, err := AcctMgr.AccountByAddress(addr) + ainfo, err := AcctMgr.Address(addr) if err != nil { return nil, &btcjson.ErrInvalidAddressOrKey } - ainfo, err := a.Address(addr) - if err != nil { - return nil, &btcjson.Error{ - Code: btcjson.ErrWallet.Code, - Message: err.Error(), - } - } - pka := ainfo.(wallet.PubKeyAddress) privkey, err := pka.PrivKey() if err != nil { @@ -1761,8 +1746,9 @@ func ValidateAddress(icmd btcjson.Cmd) (interface{}, *btcjson.Error) { result.Address = addr.EncodeAddress() result.IsValid = true - account, err := AcctMgr.AccountByAddress(addr) - if err == nil { + // We can't use AcctMgr.Address() here since we also need the account + // name. + if account, err := AcctMgr.AccountByAddress(addr); err == nil { // we ignore these errors because if this call passes this can't // realistically fail. ainfo, _ := account.Address(addr) @@ -1813,19 +1799,11 @@ func VerifyMessage(icmd btcjson.Cmd) (interface{}, *btcjson.Error) { } // First check we know about the address and get the keys. - a, err := AcctMgr.AccountByAddress(addr) + ainfo, err := AcctMgr.Address(addr) if err != nil { return nil, &btcjson.ErrInvalidAddressOrKey } - ainfo, err := a.Address(addr) - if err != nil { - return nil, &btcjson.Error{ - Code: btcjson.ErrWallet.Code, - Message: err.Error(), - } - } - pka := ainfo.(wallet.PubKeyAddress) privkey, err := pka.PrivKey() if err != nil {