diff --git a/btcjson/chainsvrcmds.go b/btcjson/chainsvrcmds.go index d751d9bce26..4535e342541 100644 --- a/btcjson/chainsvrcmds.go +++ b/btcjson/chainsvrcmds.go @@ -322,6 +322,9 @@ type TemplateRequest struct { // "proposal". Data string `json:"data,omitempty"` WorkID string `json:"workid,omitempty"` + + // "rules" + Rules []string `json:"rules,omitempty"` } // convertTemplateRequestField potentially converts the provided value as diff --git a/rpcclient/mining.go b/rpcclient/mining.go index 8717d3278fa..431054e155f 100644 --- a/rpcclient/mining.go +++ b/rpcclient/mining.go @@ -461,4 +461,39 @@ func (c *Client) SubmitBlock(block *btcutil.Block, options *btcjson.SubmitBlockO return c.SubmitBlockAsync(block, options).Receive() } -// TODO(davec): Implement GetBlockTemplate +// FutureGetBlockTemplateResponse is a future promise to deliver the result of a +// GetBlockTemplateAsync RPC invocation (or an applicable error). +type FutureGetBlockTemplateResponse chan *response + +// Receive waits for the response promised by the future and returns an error if +// any occurred when retrieving the block template. +func (r FutureGetBlockTemplateResponse) Receive() (*btcjson.GetBlockTemplateResult, error) { + res, err := receiveFuture(r) + if err != nil { + return nil, err + } + + // Unmarshal result as a getwork result object. + var result btcjson.GetBlockTemplateResult + err = json.Unmarshal(res, &result) + if err != nil { + return nil, err + } + + return &result, nil +} + +// GetBlockTemplateAsync returns an instance of a type that can be used to get the +// result of the RPC at some future time by invoking the Receive function on the +// returned instance. +// +// See GetBlockTemplate for the blocking version and more details. +func (c *Client) GetBlockTemplateAsync(req *btcjson.TemplateRequest) FutureGetBlockTemplateResponse { + cmd := btcjson.NewGetBlockTemplateCmd(req) + return c.sendCmd(cmd) +} + +// GetBlockTemplate returns a new block template for mining. +func (c *Client) GetBlockTemplate(req *btcjson.TemplateRequest) (*btcjson.GetBlockTemplateResult, error) { + return c.GetBlockTemplateAsync(req).Receive() +} diff --git a/rpcserverhelp.go b/rpcserverhelp.go index bd0f8fd7ffd..a533710daa6 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -296,6 +296,8 @@ var helpDescsEnUS = map[string]string{ "templaterequest-data": "Hex-encoded block data (only for mode=proposal)", "templaterequest-workid": "The server provided workid if provided in block template (not applicable)", + "templaterequest-rules": "Specific block rules that are to be enforced e.g. '[\"segwit\"]", + // GetBlockTemplateResultTx help. "getblocktemplateresulttx-data": "Hex-encoded transaction data (byte-for-byte)", "getblocktemplateresulttx-hash": "Hex-encoded transaction hash (little endian if treated as a 256-bit number)",