From 6e2fa5aad7d966f7d22a05bb92fb15ff0e153229 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 24 Jan 2014 22:37:18 -0600 Subject: [PATCH] Allow getaddednodeinfo result to be string slice. The getaddednode command dns flag alters the output. It is a JSON object when true and a slice of strings containing the addresses when false. Note there is a bug in bitcoind as of version 0.8.6 which returns the addresses as a JSON object with duplicate keys. This has been reported as issue 3581 on the bitcoind issue tracker. This commit allows the result for getaddednodeinfo to be either the JSON object or the string slice. --- jsonapi.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jsonapi.go b/jsonapi.go index 9ae4153d..c15cab61 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -837,7 +837,15 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) { // We handle the error condition after the switch statement. switch cmd { case "getaddednodeinfo": - var res []GetAddedNodeInfoResult + // getaddednodeinfo can either return a JSON object or a + // slice of strings depending on the verbose flag. Choose the + // right form accordingly. + var res interface{} + if strings.Contains(string(objmap["result"]), "{") { + res = []GetAddedNodeInfoResult{} + } else { + res = []string{} + } err = json.Unmarshal(objmap["result"], &res) if err == nil { result.Result = res