From 7c39a02ed1de4a8926080d8757171cbfa9d5b0b7 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 8 Apr 2014 00:01:14 -0500 Subject: [PATCH] Correct ReadResultCmd for getaddednodeinfo. The returned result was previously a []interface{} instead of a []GetAddedNodeInfoResult. This commit resolves that issue. ok @jcvernaleo --- jsonapi.go | 17 ++++++++++------- test_coverage.txt | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/jsonapi.go b/jsonapi.go index 7353bcb3..5e2e1b6c 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -888,15 +888,18 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) { // 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{} + var res []GetAddedNodeInfoResult + err = json.Unmarshal(objmap["result"], &res) + if err == nil { + result.Result = res + } } else { - res = []string{} - } - err = json.Unmarshal(objmap["result"], &res) - if err == nil { - result.Result = res + var res []string + err = json.Unmarshal(objmap["result"], &res) + if err == nil { + result.Result = res + } } case "getinfo": var res InfoResult diff --git a/test_coverage.txt b/test_coverage.txt index 22f3ce91..dd589158 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -439,7 +439,7 @@ github.com/conformal/btcjson/jsonfxns.go jsonRpcSend 62.50% (10/16) github.com/conformal/btcjson/jsoncmd.go SignRawTransactionCmd.MarshalJSON 62.50% (5/8) github.com/conformal/btcjson/jsonapi.go rpcCommand 61.54% (8/13) github.com/conformal/btcjson/jsoncmd.go GetTxOutCmd.UnmarshalJSON 59.09% (13/22) -github.com/conformal/btcjson/jsonapi.go ReadResultCmd 58.93% (66/112) +github.com/conformal/btcjson/jsonapi.go ReadResultCmd 57.89% (66/114) github.com/conformal/btcjson/jsoncmd.go GetBlockCmd.MarshalJSON 57.14% (4/7) github.com/conformal/btcjson/jsonapi.go rpcRawCommand 53.33% (8/15) github.com/conformal/btcjson/jsoncmd.go GetBlockCmd.UnmarshalJSON 50.00% (12/24) @@ -461,5 +461,5 @@ github.com/conformal/btcjson/jsoncmd.go unparsableCmd.Id 0.00% (0/1) github.com/conformal/btcjson/jsoncmd.go RegisterCustomCmd 0.00% (0/1) github.com/conformal/btcjson/jsoncmd.go unparsableCmd.SetId 0.00% (0/1) github.com/conformal/btcjson/jsoncmd.go unparsableCmd.Method 0.00% (0/1) -github.com/conformal/btcjson --------------------------------------- 78.25% (2205/2818) +github.com/conformal/btcjson --------------------------------------- 78.19% (2205/2820)