Skip to content

Commit 4fcb698

Browse files
committed
[rpc] walletcreatefundedpsbt: use wallet default RBF
1 parent febf3a8 commit 4fcb698

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ static UniValue createrawtransaction(const JSONRPCRequest& request)
406406
}, true
407407
);
408408

409-
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], request.params[3]);
409+
bool rbf = false;
410+
if (!request.params[3].isNull()) {
411+
rbf = request.params[3].isTrue();
412+
}
413+
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf);
410414

411415
return EncodeHexTx(CTransaction(rawTx));
412416
}
@@ -1362,7 +1366,11 @@ UniValue createpsbt(const JSONRPCRequest& request)
13621366
}, true
13631367
);
13641368

1365-
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], request.params[3]);
1369+
bool rbf = false;
1370+
if (!request.params[3].isNull()) {
1371+
rbf = request.params[3].isTrue();
1372+
}
1373+
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf);
13661374

13671375
// Make a blank psbt
13681376
PartiallySignedTransaction psbtx;

src/rpc/rawtransaction_util.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <util/rbf.h>
2020
#include <util/strencodings.h>
2121

22-
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, const UniValue& rbf)
22+
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, bool rbf)
2323
{
2424
if (inputs_in.isNull() || outputs_in.isNull())
2525
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, arguments 1 and 2 must be non-null");
@@ -37,8 +37,6 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
3737
rawTx.nLockTime = nLockTime;
3838
}
3939

40-
bool rbfOptIn = rbf.isTrue();
41-
4240
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
4341
const UniValue& input = inputs[idx];
4442
const UniValue& o = input.get_obj();
@@ -53,7 +51,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
5351
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
5452

5553
uint32_t nSequence;
56-
if (rbfOptIn) {
54+
if (rbf) {
5755
nSequence = MAX_BIP125_RBF_SEQUENCE; /* CTxIn::SEQUENCE_FINAL - 2 */
5856
} else if (rawTx.nLockTime) {
5957
nSequence = CTxIn::SEQUENCE_FINAL - 1;
@@ -125,7 +123,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
125123
}
126124
}
127125

128-
if (!rbf.isNull() && rawTx.vin.size() > 0 && rbfOptIn != SignalsOptInRBF(CTransaction(rawTx))) {
126+
if (rbf && rawTx.vin.size() > 0 && !SignalsOptInRBF(CTransaction(rawTx))) {
129127
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number(s) contradict replaceable option");
130128
}
131129

src/rpc/rawtransaction_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class COutPoint;
2727
UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxs, FillableSigningProvider* keystore, std::map<COutPoint, Coin>& coins, bool tempKeystore, const UniValue& hashType);
2828

2929
/** Create a transaction from univalue parameters */
30-
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, const UniValue& rbf);
30+
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, bool rbf);
3131

3232
#endif // BITCOIN_RPC_RAWTRANSACTION_UTIL_H

src/wallet/rpcwallet.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,7 +4055,7 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
40554055
{"vout_index", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, "The zero-based output index, before a change output is added."},
40564056
},
40574057
},
4058-
{"replaceable", RPCArg::Type::BOOL, /* default */ "false", "Marks this transaction as BIP125 replaceable.\n"
4058+
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Marks this transaction as BIP125 replaceable.\n"
40594059
" Allows this transaction to be replaced by a transaction with higher fees"},
40604060
{"conf_target", RPCArg::Type::NUM, /* default */ "Fallback to wallet's confirmation target", "Confirmation target (in blocks)"},
40614061
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
@@ -4090,7 +4090,13 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
40904090

40914091
CAmount fee;
40924092
int change_position;
4093-
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], request.params[3]["replaceable"]);
4093+
bool rbf = pwallet->m_signal_rbf;
4094+
const UniValue &replaceable_arg = request.params[3]["replaceable"];
4095+
if (!replaceable_arg.isNull()) {
4096+
RPCTypeCheckArgument(replaceable_arg, UniValue::VBOOL);
4097+
rbf = replaceable_arg.isTrue();
4098+
}
4099+
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf);
40944100
FundTransaction(pwallet, rawTx, fee, change_position, request.params[3]);
40954101

40964102
// Make a blank psbt

test/functional/rpc_psbt.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class PSBTTest(BitcoinTestFramework):
2727
def set_test_params(self):
2828
self.setup_clean_chain = False
2929
self.num_nodes = 3
30+
self.extra_args = [
31+
["-walletrbf=1"],
32+
[],
33+
[]
34+
]
3035

3136
def skip_test_if_missing_module(self):
3237
self.skip_if_no_wallet()
@@ -207,26 +212,26 @@ def run_test(self):
207212
# replaceable arg
208213
block_height = self.nodes[0].getblockcount()
209214
unspent = self.nodes[0].listunspent()[0]
210-
psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height+2, {"replaceable":True}, False)
215+
psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height+2, {"replaceable": False}, False)
211216
decoded_psbt = self.nodes[0].decodepsbt(psbtx_info["psbt"])
212217
for tx_in, psbt_in in zip(decoded_psbt["tx"]["vin"], decoded_psbt["inputs"]):
213-
assert_equal(tx_in["sequence"], MAX_BIP125_RBF_SEQUENCE)
218+
assert tx_in["sequence"] > MAX_BIP125_RBF_SEQUENCE
214219
assert "bip32_derivs" not in psbt_in
215220
assert_equal(decoded_psbt["tx"]["locktime"], block_height+2)
216221

217-
# Same construction with only locktime set
218-
psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height, {}, True)
222+
# Same construction with only locktime set and RBF explicitly enabled
223+
psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}], block_height, {"replaceable": True}, True)
219224
decoded_psbt = self.nodes[0].decodepsbt(psbtx_info["psbt"])
220225
for tx_in, psbt_in in zip(decoded_psbt["tx"]["vin"], decoded_psbt["inputs"]):
221-
assert tx_in["sequence"] > MAX_BIP125_RBF_SEQUENCE
226+
assert_equal(tx_in["sequence"], MAX_BIP125_RBF_SEQUENCE)
222227
assert "bip32_derivs" in psbt_in
223228
assert_equal(decoded_psbt["tx"]["locktime"], block_height)
224229

225230
# Same construction without optional arguments
226231
psbtx_info = self.nodes[0].walletcreatefundedpsbt([{"txid":unspent["txid"], "vout":unspent["vout"]}], [{self.nodes[2].getnewaddress():unspent["amount"]+1}])
227232
decoded_psbt = self.nodes[0].decodepsbt(psbtx_info["psbt"])
228233
for tx_in in decoded_psbt["tx"]["vin"]:
229-
assert tx_in["sequence"] > MAX_BIP125_RBF_SEQUENCE
234+
assert_equal(tx_in["sequence"], MAX_BIP125_RBF_SEQUENCE)
230235
assert_equal(decoded_psbt["tx"]["locktime"], 0)
231236

232237
# Make sure change address wallet does not have P2SH innerscript access to results in success

0 commit comments

Comments
 (0)