Add types for a few more commands.

Add types for getmininginfo, getrawmempool, stop, and settxfee along
with tests.
This commit is contained in:
John C. Vernaleo 2013-07-16 13:39:12 -04:00
parent 7a1a05d695
commit ed7214afda
3 changed files with 30 additions and 4 deletions

View file

@ -42,6 +42,10 @@ var resulttests = []struct {
{"decoderawtransaction", []byte(`{"error":null,"id":1,"result":{"Txid":"something"}}`), false, true}, {"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":[{"a":"b"}]}`), false, false},
{"getaddressesbyaccount", []byte(`{"error":null,"id":1,"result":["test"]}`), false, true}, {"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 // TestReadResultCmd tests that readResultCmd can properly unmarshall the

View file

@ -111,6 +111,20 @@ type Vout struct {
} `json:"scriptPubKey"` } `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 // 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 // there is no error, this should be a nil pointer to produce the null in the
// json that bitcoind produces. // json that bitcoind produces.
@ -665,7 +679,7 @@ func readResultCmd(cmd string, message []byte) (Reply, error) {
return result, err return result, err
} }
result.Result = res result.Result = res
case "getaddressesbyaccount": case "getaddressesbyaccount", "getrawmempool":
var res []string var res []string
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err != nil { if err != nil {
@ -673,12 +687,20 @@ func readResultCmd(cmd string, message []byte) (Reply, error) {
return result, err return result, err
} }
result.Result = res 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 // For commands that return a single item (or no items), we get it with
// the correct concrete type for free (but treat them separately // the correct concrete type for free (but treat them separately
// for clarity). // for clarity).
case "getblockcount", "getbalance", "getblocknumber", "getgenerate", case "getblockcount", "getbalance", "getblocknumber", "getgenerate",
"getconnetioncount", "getdifficulty", "gethashespersec", "getconnetioncount", "getdifficulty", "gethashespersec",
"setgenerate": "setgenerate", "stop", "settxfee":
err = json.Unmarshal(message, &result) err = json.Unmarshal(message, &result)
if err != nil { if err != nil {
err = fmt.Errorf("Error unmarshalling json reply: %v", err) err = fmt.Errorf("Error unmarshalling json reply: %v", err)

View file

@ -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/jsonfxns.go GetRaw 100.00% (6/6)
github.com/conformal/btcjson/jsonapi.go jsonWithArgs 100.00% (5/5) 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 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/jsonapi.go RpcCommand 66.67% (18/27)
github.com/conformal/btcjson --------------- 96.59% (425/440) github.com/conformal/btcjson --------------- 96.64% (431/446)