fix up validateaddress to use a btcjson.ValidateAddressResult.

Also fix setting the account and hex fields.

ok @jrick
This commit is contained in:
David Hill 2014-04-07 14:21:20 -04:00
parent 35bd7ef6d9
commit 08c23d858d

View file

@ -1693,58 +1693,53 @@ func ValidateAddress(icmd btcjson.Cmd) (interface{}, *btcjson.Error) {
return nil, &btcjson.ErrInternal return nil, &btcjson.ErrInternal
} }
result := btcjson.ValidateAddressResult{}
addr, err := btcutil.DecodeAddress(cmd.Address, cfg.Net()) addr, err := btcutil.DecodeAddress(cmd.Address, cfg.Net())
if err != nil { if err != nil {
return map[string]interface{}{ return result, nil
"isvalid": false,
}, nil
} }
result := map[string]interface{}{ // We could put whether or not the address is a script here,
"address": addr.EncodeAddress(), // by checking the type of "addr", however, the reference
"isvalid": true, // implementation only puts that information if the script is
// We could put whether or not the address is a script here, // "ismine", and we follow that behaviour.
// by checking the type of "addr", however, the reference result.Address = addr.EncodeAddress()
// implementation only puts that information if the script is result.IsValid = true
// "ismine", and we follow that behaviour.
}
account, err := AcctMgr.AccountByAddress(addr) account, err := AcctMgr.AccountByAddress(addr)
if err == nil { if err == nil {
// we ignore these errors because if this call passes this can't // we ignore these errors because if this call passes this can't
// realistically fail. // realistically fail.
ainfo, _ := account.AddressInfo(addr) ainfo, _ := account.AddressInfo(addr)
result["ismine"] = true result.IsMine = true
result["account"] = account result.Account = account.name
switch info := ainfo.(type) { switch info := ainfo.(type) {
case *wallet.AddressPubKeyInfo: case *wallet.AddressPubKeyInfo:
result["compressed"] = info.Compressed() result.IsCompressed = info.Compressed()
result["pubkey"] = info.Pubkey result.PubKey = info.Pubkey
case *wallet.AddressScriptInfo: case *wallet.AddressScriptInfo:
result["isscript"] = true result.IsScript = true
addrStrings := make([]string, addrStrings := make([]string,
len(info.Addresses)) len(info.Addresses))
for i, a := range info.Addresses { for i, a := range info.Addresses {
addrStrings[i] = a.EncodeAddress() addrStrings[i] = a.EncodeAddress()
} }
result["addresses"] = addrStrings result.Addresses = addrStrings
result["hex"] = info.Script result.Hex = hex.EncodeToString(info.Script)
class := info.ScriptClass class := info.ScriptClass
// script type // script type
result["script"] = class.String() result.Script = class.String()
if class == btcscript.MultiSigTy { if class == btcscript.MultiSigTy {
result["sigsrequired"] = result.SigsRequired = info.RequiredSigs
info.RequiredSigs
} }
default: default:
/* This space intentionally left blank */ /* This space intentionally left blank */
} }
} else {
result["ismine"] = false
} }
return result, nil return result, nil