From 4f4cd353194310a8562da6aae27c9c8eda8a4ff0 Mon Sep 17 00:00:00 2001 From: furszy Date: Mon, 2 Sep 2024 18:01:36 -0300 Subject: [PATCH] rpc: decouple sendtoaddress 'subtractfeefromamount' boolean parsing The 'subtractfeefromamount' arg is only boolean for sendtoaddress(). Other commands should never provide it as a boolean. --- src/wallet/rpc/spend.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index bea9b2eec18..bfe6c8812fe 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -68,10 +68,7 @@ std::set InterpretSubtractFeeFromOutputInstructions(const UniValue& sffo_in { std::set sffo_set; if (sffo_instructions.isNull()) return sffo_set; - if (sffo_instructions.isBool()) { - if (sffo_instructions.get_bool()) sffo_set.insert(0); - return sffo_set; - } + for (const auto& sffo : sffo_instructions.getValues()) { if (sffo.isStr()) { for (size_t i = 0; i < destinations.size(); ++i) { @@ -310,10 +307,13 @@ RPCHelpMan sendtoaddress() UniValue address_amounts(UniValue::VOBJ); const std::string address = request.params[0].get_str(); address_amounts.pushKV(address, request.params[1]); - std::vector recipients = CreateRecipients( - ParseOutputs(address_amounts), - InterpretSubtractFeeFromOutputInstructions(request.params[4], address_amounts.getKeys()) - ); + + std::set sffo_set; + if (!request.params[4].isNull() && request.params[4].get_bool()) { + sffo_set.insert(0); + } + + std::vector recipients{CreateRecipients(ParseOutputs(address_amounts), sffo_set)}; const bool verbose{request.params[10].isNull() ? false : request.params[10].get_bool()}; return SendMoney(*pwallet, coin_control, recipients, mapValue, verbose);