Skip to content

Commit

Permalink
rpcclient: CreateRawTransaction replaceable parameter
Browse files Browse the repository at this point in the history
Support the RPC `createrawtransaction` `replaceable` parameter, which allows disabling opt-in RBF.
  • Loading branch information
wydengyre committed Sep 15, 2023
1 parent 80f5a0f commit 87954b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions btcjson/chainsvrcmds.go
Expand Up @@ -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
Expand All @@ -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,
}
}

Expand Down
8 changes: 4 additions & 4 deletions rpcclient/rawtransactions.go
Expand Up @@ -291,23 +291,23 @@ 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)
}

// CreateRawTransaction returns a new transaction spending the provided inputs
// 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
Expand Down

0 comments on commit 87954b3

Please sign in to comment.