From 02e594f8267d63cc5adae01606ceecb0c04cf91f Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 5 Feb 2014 15:33:32 -0600 Subject: [PATCH] Add getnetworkhashps to btcctl. --- util/btcctl/btcctl.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/util/btcctl/btcctl.go b/util/btcctl/btcctl.go index 3ebc38710..b2a862fdd 100644 --- a/util/btcctl/btcctl.go +++ b/util/btcctl/btcctl.go @@ -66,6 +66,7 @@ var commandHandlers = map[string]*handlerData{ "getgenerate": {0, 0, displayGeneric, nil, makeGetGenerate, ""}, "gethashespersec": {0, 0, displayGeneric, nil, makeGetHashesPerSec, ""}, "getinfo": {0, 0, displayJSONDump, nil, makeGetInfo, ""}, + "getnetworkhashps": {0, 2, displayGeneric, []conversionHandler{toInt, toInt}, makeGetNetworkHashPS, "[blocks height]"}, "getnettotals": {0, 0, displayJSONDump, nil, makeGetNetTotals, ""}, "getnewaddress": {0, 1, displayGeneric, nil, makeGetNewAddress, "[account]"}, "getpeerinfo": {0, 0, displayJSONDump, nil, makeGetPeerInfo, ""}, @@ -375,6 +376,29 @@ func makeGetInfo(args []interface{}) (btcjson.Cmd, error) { return btcjson.NewGetInfoCmd("btcctl") } +// makeGetNetworkHashPS generates the cmd structure for getnetworkhashps +// commands. +func makeGetNetworkHashPS(args []interface{}) (btcjson.Cmd, error) { + // Create the getnetworkhashps command with defaults for the optional + // parameters. + cmd, err := btcjson.NewGetNetworkHashPSCmd("btcctl") + if err != nil { + return nil, err + } + + // Override the optional blocks if specified. + if len(args) > 0 { + cmd.Blocks = args[0].(int) + } + + // Override the optional height if specified. + if len(args) > 1 { + cmd.Height = args[1].(int) + } + + return cmd, nil +} + // makeGetNetTotals generates the cmd structure for getnettotals commands. func makeGetNetTotals(args []interface{}) (btcjson.Cmd, error) { return btcjson.NewGetNetTotalsCmd("btcctl")