Skip to content

Commit fa69c2c

Browse files
author
MarcoFalke
committed
wallet: Do not treat default constructed types as None-type
1 parent fac4e13 commit fa69c2c

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,20 @@ static std::string LabelFromValue(const UniValue& value)
201201
* @param[in] wallet Wallet reference
202202
* @param[in,out] cc Coin control to be updated
203203
* @param[in] conf_target UniValue integer; confirmation target in blocks, values between 1 and 1008 are valid per policy/fees.h;
204-
* if a fee_rate is present, 0 is allowed here as a no-op positional placeholder
205204
* @param[in] estimate_mode UniValue string; fee estimation mode, valid values are "unset", "economical" or "conservative";
206-
* if a fee_rate is present, "" is allowed here as a no-op positional placeholder
207205
* @param[in] fee_rate UniValue real; fee rate in sat/vB;
208-
* if a fee_rate is present, both conf_target and estimate_mode must either be null, or no-op
206+
* if present, both conf_target and estimate_mode must either be null, or "unset"
209207
* @param[in] override_min_fee bool; whether to set fOverrideFeeRate to true to disable minimum fee rate checks and instead
210208
* verify only that fee_rate is greater than 0
211209
* @throws a JSONRPCError if conf_target, estimate_mode, or fee_rate contain invalid values or are in conflict
212210
*/
213211
static void SetFeeEstimateMode(const CWallet& wallet, CCoinControl& cc, const UniValue& conf_target, const UniValue& estimate_mode, const UniValue& fee_rate, bool override_min_fee)
214212
{
215213
if (!fee_rate.isNull()) {
216-
if (!conf_target.isNull() && conf_target.get_int() > 0) {
214+
if (!conf_target.isNull()) {
217215
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.");
218216
}
219-
if (!estimate_mode.isNull() && !estimate_mode.get_str().empty()) {
217+
if (!estimate_mode.isNull() && estimate_mode.get_str() != "unset") {
220218
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both estimate_mode and fee_rate");
221219
}
222220
CFeeRate fee_rate_in_sat_vb{CFeeRate(AmountFromValue(fee_rate), COIN)};
@@ -473,8 +471,8 @@ static RPCHelpMan sendtoaddress()
473471
+ HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1") +
474472
"\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode using positional arguments\n"
475473
+ HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1 \"donation\" \"sean's outpost\" false true 6 economical") +
476-
"\nSend 0.1 BTC with a fee rate of 1 " + CURRENCY_ATOM + "/vB, subtract fee from amount, BIP125-replaceable, using positional arguments\n"
477-
+ HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1 \"drinks\" \"room77\" true true 0 \"\" 1") +
474+
"\nSend 0.1 BTC with a fee rate of 1.1 " + CURRENCY_ATOM + "/vB, subtract fee from amount, BIP125-replaceable, using positional arguments\n"
475+
+ HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1 \"drinks\" \"room77\" true true null \"unset\" null 1.1") +
478476
"\nSend 0.2 BTC with a confirmation target of 6 blocks in economical fee estimate mode using named arguments\n"
479477
+ HelpExampleCli("-named sendtoaddress", "address=\"" + EXAMPLE_ADDRESS[0] + "\" amount=0.2 conf_target=6 estimate_mode=\"economical\"") +
480478
"\nSend 0.5 BTC with a fee rate of 25 " + CURRENCY_ATOM + "/vB using named arguments\n"
@@ -4081,10 +4079,10 @@ static RPCHelpMan send()
40814079
RPCExamples{""
40824080
"\nSend 0.1 BTC with a confirmation target of 6 blocks in economical fee estimate mode\n"
40834081
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.1}' 6 economical\n") +
4084-
"Send 0.2 BTC with a fee rate of 1 " + CURRENCY_ATOM + "/vB using positional arguments\n"
4085-
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' 0 \"\" 1\n") +
4082+
"Send 0.2 BTC with a fee rate of 1.1 " + CURRENCY_ATOM + "/vB using positional arguments\n"
4083+
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' null \"unset\" 1.1\n") +
40864084
"Send 0.2 BTC with a fee rate of 1 " + CURRENCY_ATOM + "/vB using the options argument\n"
4087-
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' '{\"fee_rate\": 1}'\n") +
4085+
+ HelpExampleCli("send", "'{\"" + EXAMPLE_ADDRESS[0] + "\": 0.2}' null \"unset\" null '{\"fee_rate\": 1}'\n") +
40884086
"Send 0.3 BTC with a fee rate of 25 " + CURRENCY_ATOM + "/vB using named arguments\n"
40894087
+ HelpExampleCli("-named send", "outputs='{\"" + EXAMPLE_ADDRESS[0] + "\": 0.3}' fee_rate=25\n") +
40904088
"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)