Skip to content

Commit ca4a784

Browse files
author
MarcoFalke
committed
Merge #20410: wallet: Do not treat default constructed types as None-type
fa69c2c wallet: Do not treat default constructed types as None-type (MarcoFalke) fac4e13 refactor: Change pointer to reference because it can not be null (MarcoFalke) Pull request description: Equating `0==None` and `""==None` is confusing, unneeded and undocumented ACKs for top commit: jonatack: ACK fa69c2c achow101: ACK fa69c2c Sjors: tACK fa69c2c modulo `unset` Tree-SHA512: c4c8d0ad80c6697621d356a9545caf28ca2facc82bb2fa8e70eceb52372d25f0685237c73688c4b01da0e75d213c77c0d45011a8bdfe81ea783d85f045786dac
2 parents 31c9987 + fa69c2c commit ca4a784

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,23 @@ static std::string LabelFromValue(const UniValue& value)
197197
/**
198198
* Update coin control with fee estimation based on the given parameters
199199
*
200-
* @param[in] pwallet Wallet pointer
200+
* @param[in] wallet Wallet reference
201201
* @param[in,out] cc Coin control to be updated
202202
* @param[in] conf_target UniValue integer; confirmation target in blocks, values between 1 and 1008 are valid per policy/fees.h;
203-
* if a fee_rate is present, 0 is allowed here as a no-op positional placeholder
204203
* @param[in] estimate_mode UniValue string; fee estimation mode, valid values are "unset", "economical" or "conservative";
205-
* if a fee_rate is present, "" is allowed here as a no-op positional placeholder
206204
* @param[in] fee_rate UniValue real; fee rate in sat/vB;
207-
* if a fee_rate is present, both conf_target and estimate_mode must either be null, or no-op
205+
* if present, both conf_target and estimate_mode must either be null, or "unset"
208206
* @param[in] override_min_fee bool; whether to set fOverrideFeeRate to true to disable minimum fee rate checks and instead
209207
* verify only that fee_rate is greater than 0
210208
* @throws a JSONRPCError if conf_target, estimate_mode, or fee_rate contain invalid values or are in conflict
211209
*/
212-
static void SetFeeEstimateMode(const CWallet* pwallet, CCoinControl& cc, const UniValue& conf_target, const UniValue& estimate_mode, const UniValue& fee_rate, bool override_min_fee)
210+
static void SetFeeEstimateMode(const CWallet& wallet, CCoinControl& cc, const UniValue& conf_target, const UniValue& estimate_mode, const UniValue& fee_rate, bool override_min_fee)
213211
{
214212
if (!fee_rate.isNull()) {
215-
if (!conf_target.isNull() && conf_target.get_int() > 0) {
213+
if (!conf_target.isNull()) {
216214
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both conf_target and fee_rate. Please provide either a confirmation target in blocks for automatic fee estimation, or an explicit fee rate.");
217215
}
218-
if (!estimate_mode.isNull() && !estimate_mode.get_str().empty()) {
216+
if (!estimate_mode.isNull() && estimate_mode.get_str() != "unset") {
219217
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both estimate_mode and fee_rate");
220218
}
221219
cc.m_feerate = CFeeRate(AmountFromValue(fee_rate), COIN);
@@ -228,7 +226,7 @@ static void SetFeeEstimateMode(const CWallet* pwallet, CCoinControl& cc, const U
228226
throw JSONRPCError(RPC_INVALID_PARAMETER, InvalidEstimateModeErrorMessage());
229227
}
230228
if (!conf_target.isNull()) {
231-
cc.m_confirm_target = ParseConfirmTarget(conf_target, pwallet->chain().estimateMaxBlocks());
229+
cc.m_confirm_target = ParseConfirmTarget(conf_target, wallet.chain().estimateMaxBlocks());
232230
}
233231
}
234232

@@ -466,8 +464,8 @@ static RPCHelpMan sendtoaddress()
466464
+ HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1") +
467465
"\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode using positional arguments\n"
468466
+ HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1 \"donation\" \"sean's outpost\" false true 6 economical") +
469-
"\nSend 0.1 BTC with a fee rate of 1 " + CURRENCY_ATOM + "/vB, subtract fee from amount, BIP125-replaceable, using positional arguments\n"
470-
+ HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1 \"drinks\" \"room77\" true true 0 \"\" 1") +
467+
"\nSend 0.1 BTC with a fee rate of 1.1 " + CURRENCY_ATOM + "/vB, subtract fee from amount, BIP125-replaceable, using positional arguments\n"
468+
+ HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1 \"drinks\" \"room77\" true true null \"unset\" null 1.1") +
471469
"\nSend 0.2 BTC with a confirmation target of 6 blocks in economical fee estimate mode using named arguments\n"
472470
+ HelpExampleCli("-named sendtoaddress", "address=\"" + EXAMPLE_ADDRESS[0] + "\" amount=0.2 conf_target=6 estimate_mode=\"economical\"") +
473471
"\nSend 0.5 BTC with a fee rate of 25 " + CURRENCY_ATOM + "/vB using named arguments\n"
@@ -507,7 +505,7 @@ static RPCHelpMan sendtoaddress()
507505
// We also enable partial spend avoidance if reuse avoidance is set.
508506
coin_control.m_avoid_partial_spends |= coin_control.m_avoid_address_reuse;
509507

510-
SetFeeEstimateMode(pwallet, coin_control, /* conf_target */ request.params[6], /* estimate_mode */ request.params[7], /* fee_rate */ request.params[9], /* override_min_fee */ false);
508+
SetFeeEstimateMode(*pwallet, coin_control, /* conf_target */ request.params[6], /* estimate_mode */ request.params[7], /* fee_rate */ request.params[9], /* override_min_fee */ false);
511509

512510
EnsureWalletIsUnlocked(pwallet);
513511

@@ -935,7 +933,7 @@ static RPCHelpMan sendmany()
935933
coin_control.m_signal_bip125_rbf = request.params[5].get_bool();
936934
}
937935

938-
SetFeeEstimateMode(pwallet, coin_control, /* conf_target */ request.params[6], /* estimate_mode */ request.params[7], /* fee_rate */ request.params[8], /* override_min_fee */ false);
936+
SetFeeEstimateMode(*pwallet, coin_control, /* conf_target */ request.params[6], /* estimate_mode */ request.params[7], /* fee_rate */ request.params[8], /* override_min_fee */ false);
939937

940938
std::vector<CRecipient> recipients;
941939
ParseRecipients(sendTo, subtractFeeFromAmount, recipients);
@@ -3159,7 +3157,7 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
31593157
if (options.exists("replaceable")) {
31603158
coinControl.m_signal_bip125_rbf = options["replaceable"].get_bool();
31613159
}
3162-
SetFeeEstimateMode(pwallet, coinControl, options["conf_target"], options["estimate_mode"], options["fee_rate"], override_min_fee);
3160+
SetFeeEstimateMode(*pwallet, coinControl, options["conf_target"], options["estimate_mode"], options["fee_rate"], override_min_fee);
31633161
}
31643162
} else {
31653163
// if options is null and not a bool
@@ -3487,7 +3485,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
34873485
if (options.exists("replaceable")) {
34883486
coin_control.m_signal_bip125_rbf = options["replaceable"].get_bool();
34893487
}
3490-
SetFeeEstimateMode(pwallet, coin_control, conf_target, options["estimate_mode"], options["fee_rate"], /* override_min_fee */ false);
3488+
SetFeeEstimateMode(*pwallet, coin_control, conf_target, options["estimate_mode"], options["fee_rate"], /* override_min_fee */ false);
34913489
}
34923490

34933491
// Make sure the results are valid at least up to the most recent block
@@ -4076,10 +4074,10 @@ static RPCHelpMan send()
40764074
RPCExamples{""
40774075
"\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode\n"
40784076
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.1}' 6 economical\n") +
4079-
"Send 0.2 BTC with a fee rate of 1 " + CURRENCY_ATOM + "/vB using positional arguments\n"
4080-
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' 0 \"\" 1\n") +
4077+
"Send 0.2 BTC with a fee rate of 1.1 " + CURRENCY_ATOM + "/vB using positional arguments\n"
4078+
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' null \"unset\" 1.1\n") +
40814079
"Send 0.2 BTC with a fee rate of 1 " + CURRENCY_ATOM + "/vB using the options argument\n"
4082-
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' '{\"fee_rate\": 1}'\n") +
4080+
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' null \"unset\" null '{\"fee_rate\": 1}'\n") +
40834081
"Send 0.3 BTC with a fee rate of 25 " + CURRENCY_ATOM + "/vB using named arguments\n"
40844082
+ HelpExampleCli("-named send", "outputs='{\"" + EXAMPLE_ADDRESS[0] + "\": 0.3}' fee_rate=25\n") +
40854083
"Create a transaction that should confirm the next block, with a specific input, and return result without adding to wallet or broadcasting to the network\n"

test/functional/wallet_basic.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ def run_test(self):
235235
fee_rate_btc_kvb = fee_rate_sat_vb * 1e3 / 1e8
236236
explicit_fee_rate_btc_kvb = Decimal(fee_rate_btc_kvb) / 1000
237237

238-
# Passing conf_target 0, estimate_mode "" as placeholder arguments should allow fee_rate to apply.
239-
txid = self.nodes[2].sendmany(amounts={address: 10}, conf_target=0, estimate_mode="", fee_rate=fee_rate_sat_vb)
238+
txid = self.nodes[2].sendmany(amounts={address: 10}, fee_rate=fee_rate_sat_vb)
240239
self.nodes[2].generate(1)
241240
self.sync_all(self.nodes[0:3])
242241
balance = self.nodes[2].getbalance()
@@ -407,8 +406,7 @@ def run_test(self):
407406
fee_rate_sat_vb = 2
408407
fee_rate_btc_kvb = fee_rate_sat_vb * 1e3 / 1e8
409408

410-
# Passing conf_target 0, estimate_mode "" as placeholder arguments should allow fee_rate to apply.
411-
txid = self.nodes[2].sendtoaddress(address=address, amount=amount, conf_target=0, estimate_mode="", fee_rate=fee_rate_sat_vb)
409+
txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=fee_rate_sat_vb)
412410
tx_size = self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])
413411
self.nodes[0].generate(1)
414412
self.sync_all(self.nodes[0:3])

test/functional/wallet_send.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,16 @@ def run_test(self):
260260
res2 = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=1, add_to_wallet=False)
261261
assert_equal(self.nodes[1].decodepsbt(res1["psbt"])["fee"], self.nodes[1].decodepsbt(res2["psbt"])["fee"])
262262

263-
# Passing conf_target 0, estimate_mode "" as placeholder arguments should allow fee_rate to apply.
264-
res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, conf_target=0, estimate_mode="", fee_rate=7, add_to_wallet=False)
263+
res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=7, add_to_wallet=False)
265264
fee = self.nodes[1].decodepsbt(res["psbt"])["fee"]
266265
assert_fee_amount(fee, Decimal(len(res["hex"]) / 2), Decimal("0.00007"))
267266

268-
res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=2, add_to_wallet=False)
267+
# "unset" and None are treated the same for estimate_mode
268+
res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, fee_rate=2, estimate_mode="unset", add_to_wallet=False)
269269
fee = self.nodes[1].decodepsbt(res["psbt"])["fee"]
270270
assert_fee_amount(fee, Decimal(len(res["hex"]) / 2), Decimal("0.00002"))
271271

272-
# Passing conf_target 0, estimate_mode "" as placeholder arguments should allow fee_rate to apply.
273-
res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_conf_target=0, arg_estimate_mode="", arg_fee_rate=4.531, add_to_wallet=False)
272+
res = self.test_send(from_wallet=w0, to_wallet=w1, amount=1, arg_fee_rate=4.531, add_to_wallet=False)
274273
fee = self.nodes[1].decodepsbt(res["psbt"])["fee"]
275274
assert_fee_amount(fee, Decimal(len(res["hex"]) / 2), Decimal("0.00004531"))
276275

0 commit comments

Comments
 (0)