diff --git a/internal_test.go b/internal_test.go index ef1f1021..1647f379 100644 --- a/internal_test.go +++ b/internal_test.go @@ -51,6 +51,8 @@ var resulttests = []struct { {"validateaddress", []byte(`{"error":null,"id":1,"result":{false}}`), false, false}, {"signrawtransaction", []byte(`{"error":null,"id":1,"result":{"hex":"something","complete":false}}`), false, true}, {"signrawtransaction", []byte(`{"error":null,"id":1,"result":{false}}`), false, false}, + {"listunspent", []byte(`{"error":null,"id":1,"result":[{"txid":"something"}]}`), false, true}, + {"listunspent", []byte(`{"error":null,"id":1,"result":[{"txid"}]}`), false, false}, } // TestReadResultCmd tests that readResultCmd can properly unmarshall the diff --git a/jsonapi.go b/jsonapi.go index aa164e97..4811dca8 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -141,6 +141,16 @@ type SignRawTransactionResult struct { Complete bool `json:"complete"` } +type ListUnSpentResult struct { + TxId string `json:"txid"` + Vout float64 `json:"vout"` + Address string `json:"address"` + Account string `json:"account"` + ScriptPubKey string `json:"scriptPubKey"` + Amount float64 `json:"amount"` + Confirmations float64 `json:"confirmations"` +} + // Error models the error field of the json returned by a bitcoin client. When // there is no error, this should be a nil pointer to produce the null in the // json that bitcoind produces. @@ -712,6 +722,12 @@ func readResultCmd(cmd string, message []byte) (Reply, error) { if err == nil { result.Result = res } + case "listunspent": + var res []ListUnSpentResult + err = json.Unmarshal(objmap["result"], &res) + if err == nil { + result.Result = res + } // For commands that return a single item (or no items), we get it with // the correct concrete type for free (but treat them separately // for clarity). diff --git a/test_coverage.txt b/test_coverage.txt index ca17db99..2b8ab6b6 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,6 +1,6 @@ github.com/conformal/btcjson/jsonapi.go CreateMessage 100.00% (310/310) -github.com/conformal/btcjson/jsonapi.go readResultCmd 100.00% (59/59) +github.com/conformal/btcjson/jsonapi.go readResultCmd 100.00% (63/63) github.com/conformal/btcjson/jsonapi.go JSONToAmount 100.00% (15/15) github.com/conformal/btcjson/jsonfxns.go MarshallAndSend 100.00% (7/7) github.com/conformal/btcjson/jsonfxns.go jsonRpcSend 100.00% (7/7) @@ -8,5 +8,5 @@ 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 RpcCommand 66.67% (18/27) -github.com/conformal/btcjson --------------- 97.95% (430/439) +github.com/conformal/btcjson --------------- 97.97% (434/443)