diff --git a/internal_test.go b/internal_test.go index 665618e66..01afd6a9a 100644 --- a/internal_test.go +++ b/internal_test.go @@ -42,6 +42,10 @@ var resulttests = []struct { {"decoderawtransaction", []byte(`{"error":null,"id":1,"result":{"Txid":"something"}}`), false, true}, {"getaddressesbyaccount", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, {"getaddressesbyaccount", []byte(`{"error":null,"id":1,"result":["test"]}`), false, true}, + {"getmininginfo", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, + {"getmininginfo", []byte(`{"error":null,"id":1,"result":{"generate":true}}`), false, true}, + {"getrawmempool", []byte(`{"error":null,"id":1,"result":[{"a":"b"}]}`), false, false}, + {"getrawmempool", []byte(`{"error":null,"id":1,"result":["test"]}`), false, true}, } // TestReadResultCmd tests that readResultCmd can properly unmarshall the diff --git a/jsonapi.go b/jsonapi.go index abccdc031..1a7d5b03c 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -111,6 +111,20 @@ type Vout struct { } `json:"scriptPubKey"` } +// GetMiningInfoResult models the data from the getmininginfo command. +type GetMiningInfoResult struct { + CurrentBlockSize float64 `json:"currentblocksize"` + Difficulty float64 `json:"difficulty"` + Errors string `json:"errors"` + Generate bool `json:"generate"` + GenProcLimit float64 `json:"genproclimit"` + PooledTx float64 `json:"pooledtx"` + Testnet bool `json:"testnet"` + Blocks float64 `json:"blocks"` + CurrentBlockTx float64 `json:"currentblocktx"` + HashesPerSec float64 `json:"hashespersec"` +} + // 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. @@ -665,7 +679,7 @@ func readResultCmd(cmd string, message []byte) (Reply, error) { return result, err } result.Result = res - case "getaddressesbyaccount": + case "getaddressesbyaccount", "getrawmempool": var res []string err = json.Unmarshal(objmap["result"], &res) if err != nil { @@ -673,12 +687,20 @@ func readResultCmd(cmd string, message []byte) (Reply, error) { return result, err } result.Result = res + case "getmininginfo": + var res GetMiningInfoResult + 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 (or no items), we get it with // the correct concrete type for free (but treat them separately // for clarity). case "getblockcount", "getbalance", "getblocknumber", "getgenerate", "getconnetioncount", "getdifficulty", "gethashespersec", - "setgenerate": + "setgenerate", "stop", "settxfee": err = json.Unmarshal(message, &result) if err != nil { err = fmt.Errorf("Error unmarshalling json reply: %v", err) diff --git a/test_coverage.txt b/test_coverage.txt index 642e52611..ca6c25170 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -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% (54/60) +github.com/conformal/btcjson/jsonapi.go readResultCmd 90.91% (60/66) github.com/conformal/btcjson/jsonapi.go RpcCommand 66.67% (18/27) -github.com/conformal/btcjson --------------- 96.59% (425/440) +github.com/conformal/btcjson --------------- 96.64% (431/446)