From a6943bd839ac94d932fa5827bf84627b04d0aa33 Mon Sep 17 00:00:00 2001 From: duggavo <> Date: Thu, 18 May 2023 19:31:22 +0200 Subject: [PATCH] get_block_template: allow setting extra_nonce --- rpc/daemon/jsonrpc.go | 11 ++--------- rpc/daemon/types.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rpc/daemon/jsonrpc.go b/rpc/daemon/jsonrpc.go index c77c8b6..7ab2a10 100644 --- a/rpc/daemon/jsonrpc.go +++ b/rpc/daemon/jsonrpc.go @@ -15,7 +15,6 @@ const ( methodGetBlockHeadersRange = "get_block_headers_range" methodGetBlockHeaderByHash = "get_block_header_by_hash" methodGetBlockHeaderByHeight = "get_block_header_by_height" - methodGetBlockTemplate = "get_block_template" methodGetCoinbaseTxSum = "get_coinbase_tx_sum" methodGetConnections = "get_connections" methodGetFeeEstimate = "get_fee_estimate" @@ -216,16 +215,10 @@ func (c *Client) RelayTx( } // GetBlockTemplate gets a block template on which mining a new block. -func (c *Client) GetBlockTemplate( - ctx context.Context, walletAddress string, reserveSize uint, -) (*GetBlockTemplateResult, error) { +func (c *Client) GetBlockTemplate(ctx context.Context, params GetBlockTemplateParams) (*GetBlockTemplateResult, error) { resp := &GetBlockTemplateResult{} - params := map[string]interface{}{ - "wallet_address": walletAddress, - "reserve_size": reserveSize, - } - err := c.JSONRPC(ctx, methodGetBlockTemplate, params, resp) + err := c.JSONRPC(ctx, "get_block_template", params, resp) if err != nil { return nil, fmt.Errorf("jsonrpc: %w", err) } diff --git a/rpc/daemon/types.go b/rpc/daemon/types.go index 7a90fd1..b4257ce 100644 --- a/rpc/daemon/types.go +++ b/rpc/daemon/types.go @@ -236,6 +236,16 @@ type GetInfoResult struct { RPCResultFooter `json:",inline"` } +type GetBlockTemplateParams struct { + WalletAddress string `json:"wallet_address"` + + // ReserveSize reserves X byte in the block header for the extra nonce. + ReserveSize uint `json:"reserve_size,omitempty"` + + // ExtraNonce is the hex string representing the extra nonce. + ExtraNonce string `json:"extra_nonce,omitempty"` +} + // GetBlockTemplateResult is the result of a call to the GetBlockTemplate RPC // method. type GetBlockTemplateResult struct {