Add acctmgr.Address to look up any known address.
Use where possible to shorten things.
This commit is contained in:
parent
e39fa32487
commit
49adb8312f
2 changed files with 17 additions and 28 deletions
11
acctmgr.go
11
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)
|
||||
|
|
34
rpcserver.go
34
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 {
|
||||
|
|
Loading…
Reference in a new issue