From f14d2edbffde3b17c776e4d6eee84242fae0ee2f Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 7 Oct 2013 22:17:27 -0400 Subject: [PATCH] Return errors for getaddressesbyaccount command --- cmdmgr.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmdmgr.go b/cmdmgr.go index 46a5425..75f03dc 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -235,22 +235,34 @@ func ReplySuccess(reply chan []byte, id interface{}, result interface{}) { // GetAddressesByAccount replies with all addresses for an account. func GetAddressesByAccount(reply chan []byte, msg *btcjson.Message) { + e := InvalidParams + // TODO(jrick): check if we can make btcjson.Message.Params // a []interface{} to avoid this. params, ok := msg.Params.([]interface{}) if !ok { - log.Error("GetAddressesByAccount: Cannot parse parameters.") + ReplyError(reply, msg.Id, &e) return } + account, ok := params[0].(string) + if !ok { + e.Message = "account is not a string" + ReplyError(reply, msg.Id, &e) + return + } + var result interface{} wallets.RLock() - w := wallets.m[params[0].(string)] + w := wallets.m[account] wallets.RUnlock() + if w != nil { result = w.Wallet.GetActiveAddresses() } else { - result = []interface{}{} + ReplyError(reply, msg.Id, &WalletInvalidAccountName) + return } + ReplySuccess(reply, msg.Id, result) }