Skip to content

Commit

Permalink
btcjson+rpcclient: restore bitcoind compatibility
Browse files Browse the repository at this point in the history
The PR btcsuite#1594 introduced a change that made the order of parameters
relevant, if one of them is nil. This makes it harder to be backward
compatible with the same JSON message if an existing parameter in
bitcoind was re-purposed to have a different meaning.
  • Loading branch information
guggero committed Nov 12, 2020
1 parent 65d2b7a commit 39f46c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions btcjson/chainsvrcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,14 @@ func NewSearchRawTransactionsCmd(address string, verbose, skip, count *int, vinE
// SendRawTransactionCmd defines the sendrawtransaction JSON-RPC command.
type SendRawTransactionCmd struct {
HexTx string
MaxFeeRate *int32
AllowHighFees *bool `jsonrpcdefault:"false"`
}

// SendRawTransactionBitcoindCmd defines the sendrawtransaction JSON-RPC command
// that is used for bitcoind post 0.19.0.
type SendRawTransactionBitcoindCmd struct {
HexTx string
MaxFeeRate *int32
}

Expand All @@ -842,8 +849,8 @@ func NewSendRawTransactionCmd(hexTx string, allowHighFees *bool) *SendRawTransac
// sendrawtransaction JSON-RPC command to a bitcoind node.
//
// A 0 maxFeeRate indicates that a maximum fee rate won't be enforced.
func NewBitcoindSendRawTransactionCmd(hexTx string, maxFeeRate int32) *SendRawTransactionCmd {
return &SendRawTransactionCmd{
func NewBitcoindSendRawTransactionCmd(hexTx string, maxFeeRate int32) *SendRawTransactionBitcoindCmd {
return &SendRawTransactionBitcoindCmd{
HexTx: hexTx,
MaxFeeRate: &maxFeeRate,
}
Expand Down
2 changes: 1 addition & 1 deletion rpcclient/rawtransactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (c *Client) SendRawTransactionAsync(tx *wire.MsgTx, allowHighFees bool) Fut
return newFutureError(err)
}

var cmd *btcjson.SendRawTransactionCmd
var cmd interface{}
switch version {
// Starting from bitcoind v0.19.0, the MaxFeeRate field should be used.
case BitcoindPost19:
Expand Down

0 comments on commit 39f46c4

Please sign in to comment.