Return errors for getaddressesbyaccount command

This commit is contained in:
Josh Rickmar 2013-10-07 22:17:27 -04:00
parent 7e3edab24b
commit f14d2edbff

View file

@ -235,22 +235,34 @@ func ReplySuccess(reply chan []byte, id interface{}, result interface{}) {
// GetAddressesByAccount replies with all addresses for an account. // GetAddressesByAccount replies with all addresses for an account.
func GetAddressesByAccount(reply chan []byte, msg *btcjson.Message) { func GetAddressesByAccount(reply chan []byte, msg *btcjson.Message) {
e := InvalidParams
// TODO(jrick): check if we can make btcjson.Message.Params // TODO(jrick): check if we can make btcjson.Message.Params
// a []interface{} to avoid this. // a []interface{} to avoid this.
params, ok := msg.Params.([]interface{}) params, ok := msg.Params.([]interface{})
if !ok { if !ok {
log.Error("GetAddressesByAccount: Cannot parse parameters.") ReplyError(reply, msg.Id, &e)
return return
} }
account, ok := params[0].(string)
if !ok {
e.Message = "account is not a string"
ReplyError(reply, msg.Id, &e)
return
}
var result interface{} var result interface{}
wallets.RLock() wallets.RLock()
w := wallets.m[params[0].(string)] w := wallets.m[account]
wallets.RUnlock() wallets.RUnlock()
if w != nil { if w != nil {
result = w.Wallet.GetActiveAddresses() result = w.Wallet.GetActiveAddresses()
} else { } else {
result = []interface{}{} ReplyError(reply, msg.Id, &WalletInvalidAccountName)
return
} }
ReplySuccess(reply, msg.Id, result) ReplySuccess(reply, msg.Id, result)
} }