Use ReplySuccess() to send successful JSON replies

This commit is contained in:
Josh Rickmar 2013-08-21 13:43:05 -04:00
parent 8f38a43964
commit b0f6a70d40

View file

@ -199,7 +199,7 @@ func ReplyError(reply chan []byte, id interface{}, e *btcjson.Error) {
func ReplySuccess(reply chan []byte, id interface{}, result interface{}) { func ReplySuccess(reply chan []byte, id interface{}, result interface{}) {
r := btcjson.Reply{ r := btcjson.Reply{
Result: result, Result: result,
Id: &id, Id: &id,
} }
if mr, err := json.Marshal(r); err != nil { if mr, err := json.Marshal(r); err != nil {
reply <- mr reply <- mr
@ -211,21 +211,14 @@ func GetAddressesByAccount(reply chan []byte, msg []byte) {
var v map[string]interface{} var v map[string]interface{}
json.Unmarshal(msg, &v) json.Unmarshal(msg, &v)
params := v["params"].([]interface{}) params := v["params"].([]interface{})
id := v["id"]
r := btcjson.Reply{ var result interface{}
Id: &id,
}
if w := wallets[params[0].(string)]; w != nil { if w := wallets[params[0].(string)]; w != nil {
r.Result = w.GetActiveAddresses() result = w.GetActiveAddresses()
} else { } else {
r.Result = []interface{}{} result = []interface{}{}
} }
mr, err := json.Marshal(r) ReplySuccess(reply, v["id"], result)
if err != nil {
log.Info("Error marshalling reply: %v", err)
return
}
reply <- mr
} }
// GetNewAddress gets or generates a new address for an account. // GetNewAddress gets or generates a new address for an account.
@ -238,17 +231,7 @@ func GetNewAddress(reply chan []byte, msg []byte) {
if len(params) == 0 || params[0].(string) == "" { if len(params) == 0 || params[0].(string) == "" {
if w := wallets[""]; w != nil { if w := wallets[""]; w != nil {
addr := w.NextUnusedAddress() addr := w.NextUnusedAddress()
id := v["id"] ReplySuccess(reply, v["id"], addr)
r := btcjson.Reply{
Result: addr,
Id: &id,
}
mr, err := json.Marshal(r)
if err != nil {
log.Info("Error marshalling reply: %v", err)
return
}
reply <- mr
} }
} }
} }