From 87954b3a9de10b457c312c47003910230cf0a54a Mon Sep 17 00:00:00 2001 From: wydengyre Date: Fri, 15 Sep 2023 16:26:16 +0100 Subject: [PATCH] rpcclient: CreateRawTransaction replaceable parameter Support the RPC `createrawtransaction` `replaceable` parameter, which allows disabling opt-in RBF. --- btcjson/chainsvrcmds.go | 16 +++++++++------- rpcclient/rawtransactions.go | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/btcjson/chainsvrcmds.go b/btcjson/chainsvrcmds.go index aa1d4415da5..6f8550eac6a 100644 --- a/btcjson/chainsvrcmds.go +++ b/btcjson/chainsvrcmds.go @@ -57,9 +57,10 @@ type TransactionInput struct { // CreateRawTransactionCmd defines the createrawtransaction JSON-RPC command. type CreateRawTransactionCmd struct { - Inputs []TransactionInput - Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC - LockTime *int64 + Inputs []TransactionInput + Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC + LockTime *int64 + Replaceable *bool } // NewCreateRawTransactionCmd returns a new instance which can be used to issue @@ -68,16 +69,17 @@ type CreateRawTransactionCmd struct { // Amounts are in BTC. Passing in nil and the empty slice as inputs is equivalent, // both gets interpreted as the empty slice. func NewCreateRawTransactionCmd(inputs []TransactionInput, amounts map[string]float64, - lockTime *int64) *CreateRawTransactionCmd { + lockTime *int64, replaceable *bool) *CreateRawTransactionCmd { // to make sure we're serializing this to the empty list and not null, we // explicitly initialize the list if inputs == nil { inputs = []TransactionInput{} } return &CreateRawTransactionCmd{ - Inputs: inputs, - Amounts: amounts, - LockTime: lockTime, + Inputs: inputs, + Amounts: amounts, + LockTime: lockTime, + Replaceable: replaceable, } } diff --git a/rpcclient/rawtransactions.go b/rpcclient/rawtransactions.go index 1df61952201..06ea7f2bd53 100644 --- a/rpcclient/rawtransactions.go +++ b/rpcclient/rawtransactions.go @@ -291,13 +291,13 @@ func (r FutureCreateRawTransactionResult) Receive() (*wire.MsgTx, error) { // // See CreateRawTransaction for the blocking version and more details. func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput, - amounts map[btcutil.Address]btcutil.Amount, lockTime *int64) FutureCreateRawTransactionResult { + amounts map[btcutil.Address]btcutil.Amount, lockTime *int64, replaceable *bool) FutureCreateRawTransactionResult { convertedAmts := make(map[string]float64, len(amounts)) for addr, amount := range amounts { convertedAmts[addr.String()] = amount.ToBTC() } - cmd := btcjson.NewCreateRawTransactionCmd(inputs, convertedAmts, lockTime) + cmd := btcjson.NewCreateRawTransactionCmd(inputs, convertedAmts, lockTime, replaceable) return c.SendCmd(cmd) } @@ -305,9 +305,9 @@ func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput, // and sending to the provided addresses. If the inputs are either nil or an // empty slice, it is interpreted as an empty slice. func (c *Client) CreateRawTransaction(inputs []btcjson.TransactionInput, - amounts map[btcutil.Address]btcutil.Amount, lockTime *int64) (*wire.MsgTx, error) { + amounts map[btcutil.Address]btcutil.Amount, lockTime *int64, replaceable *bool) (*wire.MsgTx, error) { - return c.CreateRawTransactionAsync(inputs, amounts, lockTime).Receive() + return c.CreateRawTransactionAsync(inputs, amounts, lockTime, replaceable).Receive() } // FutureSendRawTransactionResult is a future promise to deliver the result