Add more concrete types.
Add concrete return type for getaddressesbyaccount and make some of the other command type handeling more explicit in the code.
This commit is contained in:
parent
39a1be8682
commit
e3c9ebd26f
3 changed files with 21 additions and 2 deletions
|
@ -37,6 +37,8 @@ var resulttests = []struct {
|
|||
{"getblock", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false},
|
||||
{"getrawtransaction", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false},
|
||||
{"decoderawtransaction", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false},
|
||||
{"getaddressesbyaccount", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false},
|
||||
{"getaddressesbyaccount", []byte(`{"error":null,"id":1,"result":["test"]}`), false, true},
|
||||
}
|
||||
|
||||
// TestReadResultCmd tests that readResultCmd can properly unmarshall the
|
||||
|
|
17
jsonapi.go
17
jsonapi.go
|
@ -665,6 +665,23 @@ func readResultCmd(cmd string, message []byte) (Reply, error) {
|
|||
return result, err
|
||||
}
|
||||
result.Result = res
|
||||
case "getaddressesbyaccount":
|
||||
var res []string
|
||||
err = json.Unmarshal(objmap["result"], &res)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error unmarshalling json reply: %v", err)
|
||||
return result, err
|
||||
}
|
||||
result.Result = res
|
||||
// For commands that return a single item, we get it with the
|
||||
// correct concrete type for free (but treat them seperately
|
||||
// for clarity.
|
||||
case "getblockcount":
|
||||
err = json.Unmarshal(message, &result)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error unmarshalling json reply: %v", err)
|
||||
return result, err
|
||||
}
|
||||
// For anything else put it in an interface. All the data is still
|
||||
// there, just a little less convenient to deal with.
|
||||
default:
|
||||
|
|
|
@ -6,7 +6,7 @@ github.com/conformal/btcjson/jsonfxns.go MarshallAndSend 100.00% (7/7)
|
|||
github.com/conformal/btcjson/jsonfxns.go GetRaw 100.00% (6/6)
|
||||
github.com/conformal/btcjson/jsonapi.go jsonWithArgs 100.00% (5/5)
|
||||
github.com/conformal/btcjson/jsonapi.go IsValidIdType 100.00% (3/3)
|
||||
github.com/conformal/btcjson/jsonapi.go readResultCmd 90.00% (45/50)
|
||||
github.com/conformal/btcjson/jsonapi.go readResultCmd 85.00% (51/60)
|
||||
github.com/conformal/btcjson/jsonapi.go RpcCommand 66.67% (18/27)
|
||||
github.com/conformal/btcjson --------------- 96.74% (416/430)
|
||||
github.com/conformal/btcjson --------------- 95.91% (422/440)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue