Add proper result type for listunspent.

This commit is contained in:
John C. Vernaleo 2013-08-09 15:34:24 -04:00
parent b28cded23e
commit da7e872354
3 changed files with 20 additions and 2 deletions

View file

@ -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

View file

@ -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).

View file

@ -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)