Merge bitcoin/bitcoin#36384: rpc: Use self.Arg<_>(name) helper over manual and duplicate parsing
What changed, and why it matters
This is a code cleanup change in Bitcoin Core's RPC (remote procedure call) handling. It replaces manual argument parsing with a helper called self.Arg<_>(name). The goal is to reduce duplicated code and make defaults easier to maintain. There is no obvious security vulnerability introduced, but any refactor touching many RPC commands carries a small risk of subtle behavior changes.
Review the refactor for any unintended semantic changes, especially around default values, alias handling, and the uint64_t maxtries change. Run the updated rpc_tests and RPC functional tests. No immediate security patch is indicated.
Security signals we found
Large refactor of RPC argument parsing across many commands
Behavior change: GetParamIndex now matches only the first argument name, not aliases
Type change: generatetoaddress maxtries parsed as uint64_t instead of int
New Arg<> instantiations for double and int64_t
No explicit security claims by the vendor
Evidence from the diff
The commit refactors RPC argument parsing across src/rpc/.cpp and src/wallet/rpc/.cpp to use the existing RPCMethod::Arg
Changed components
src/rpc/blockchain.cppsrc/rpc/fees.cppsrc/rpc/mempool.cppsrc/rpc/mining.cppsrc/rpc/net.cppsrc/rpc/rawtransaction.cppsrc/rpc/util.cppsrc/rpc/util.hsrc/test/rpc_tests.cppsrc/wallet/rpc/addresses.cppsrc/wallet/rpc/backup.cppsrc/wallet/rpc/coins.cppsrc/wallet/rpc/spend.cppsrc/wallet/rpc/transactions.cppsrc/wallet/rpc/wallet.cppInspect captured patch +86 / −137
### src/rpc/blockchain.cpp
@@ -349,9 +349,7 @@ static RPCMethod waitfornewblock()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- int timeout = 0;
- if (!request.params[0].isNull())
- timeout = request.params[0].getInt<int>();
+ const int timeout{self.Arg<int>("timeout")};
if (timeout < 0) throw JSONRPCError(RPC_MISC_ERROR, "Negative timeout");
NodeContext& node = EnsureAnyNodeContext(request.context);
@@ -408,12 +406,10 @@ static RPCMethod waitforblock()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- int timeout = 0;
+ const int timeout{self.Arg<int>("timeout")};
uint256 hash(ParseHashV(request.params[0], "blockhash"));
- if (!request.params[1].isNull())
- timeout = request.params[1].getInt<int>();
if (timeout < 0) throw JSONRPCError(RPC_MISC_ERROR, "Negative timeout");
NodeContext& node = EnsureAnyNodeContext(request.context);
@@ -470,12 +466,10 @@ static RPCMethod waitforblockheight()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- int timeout = 0;
+ const int timeout{self.Arg<int>("timeout")};
int height = request.params[0].getInt<int>();
- if (!request.params[1].isNull())
- timeout = request.params[1].getInt<int>();
if (timeout < 0) throw JSONRPCError(RPC_MISC_ERROR, "Negative timeout");
NodeContext& node = EnsureAnyNodeContext(request.context);
@@ -677,9 +671,7 @@ static RPCMethod getblockheader()
{
uint256 hash(ParseHashV(request.params[0], "hash"));
- bool fVerbose = true;
- if (!request.params[1].isNull())
- fVerbose = request.params[1].get_bool();
+ const bool fVerbose{self.Arg<bool>("verbose")};
const CBlockIndex* pblockindex;
const CBlockIndex* tip;
@@ -1105,7 +1097,7 @@ static RPCMethod gettxoutsetinfo()
UniValue ret(UniValue::VOBJ);
const CoinStatsHashType hash_type{ParseHashType(self.Arg<std::string_view>("hash_type"))};
- bool index_requested = request.params[2].isNull() || request.params[2].get_bool();
+ const bool index_requested{self.Arg<bool>("use_index")};
NodeContext& node = EnsureAnyNodeContext(request.context);
ChainstateManager& chainman = EnsureChainman(node);
@@ -1257,9 +1249,7 @@ static RPCMethod gettxout()
auto hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
COutPoint out{hash, request.params[1].getInt<uint32_t>()};
- bool fMempool = true;
- if (!request.params[2].isNull())
- fMempool = request.params[2].get_bool();
+ const bool fMempool{self.Arg<bool>("include_mempool")};
Chainstate& active_chainstate = chainman.ActiveChainstate();
CCoinsViewCache* coins_view = &active_chainstate.CoinsTip();
@@ -1298,21 +1288,21 @@ static RPCMethod verifychain()
return RPCMethod{
"verifychain",
"Verifies blockchain database.\n",
- {
- {"checklevel", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL)},
- strprintf("How thorough the block verification is:\n%s", MakeUnorderedList(CHECKLEVEL_DOC))},
- {"nblocks", RPCArg::Type::NUM, RPCArg::DefaultHint{strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS)}, "The number of blocks to check."},
- },
- RPCResult{
+ {
+ {"checklevel", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_CHECKLEVEL},
+ strprintf("How thorough the block verification is (range 0-4):\n%s", MakeUnorderedList(CHECKLEVEL_DOC))},
+ {"nblocks", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_CHECKBLOCKS}, "The number of blocks to check (0=all)."},
+ },
+ RPCResult{
RPCResult::Type::BOOL, "", "Verification finished successfully. If false, check debug log for reason."},
RPCExamples{
HelpExampleCli("verifychain", "")
+ HelpExampleRpc("verifychain", "")
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- const int check_level{request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].getInt<int>()};
- const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].getInt<int>()};
+ const int check_level{self.Arg<int>("checklevel")};
+ const int check_depth{self.Arg<int>("nblocks")};
ChainstateManager& chainman = EnsureAnyChainman(request.context);
LOCK(cs_main);
@@ -2665,13 +2655,10 @@ static RPCMethod scanblocks()
{
LOCK(cs_main);
CChain& active_chain = chainman.ActiveChain();
- start_index = active_chain.Genesis();
+ start_index = active_chain[self.Arg<int>("start_height")];
stop_block = active_chain.Tip(); // If no stop block is provided, stop at the chain tip.
- if (!request.params[2].isNull()) {
- start_index = active_chain[request.params[2].getInt<int>()];
- if (!start_index) {
- throw JSONRPCError(RPC_MISC_ERROR, "Invalid start_height");
- }
+ if (!start_index) {
+ throw JSONRPCError(RPC_MISC_ERROR, "Invalid start_height");
}
if (!request.params[3].isNull()) {
stop_block = active_chain[request.params[3].getInt<int>()];
@@ -2935,10 +2922,7 @@ static RPCMethod getdescriptoractivity()
}
}
- bool search_mempool = true;
- if (!request.params[2].isNull()) {
- search_mempool = request.params[2].get_bool();
- }
+ const bool search_mempool{self.Arg<bool>("include_mempool")};
if (search_mempool) {
const CTxMemPool& mempool = EnsureMemPool(node);
### src/rpc/fees.cpp
@@ -221,10 +221,7 @@ static RPCMethod estimaterawfee()
CHECK_NONFATAL(node.validation_signals)->SyncWithValidationInterfaceQueue();
unsigned int max_target = fee_estimator_man.MaximumTarget();
unsigned int conf_target = ParseConfirmTarget(request.params[0], max_target);
- double threshold = 0.95;
- if (!request.params[1].isNull()) {
- threshold = request.params[1].get_real();
- }
+ const double threshold{self.Arg<double>("threshold")};
if (threshold < 0 || threshold > 1) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid threshold");
}
### src/rpc/mempool.cpp
@@ -126,7 +126,7 @@ static RPCMethod sendrawtransaction()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- const CAmount max_burn_amount = request.params[2].isNull() ? 0 : AmountFromValue(request.params[2]);
+ const CAmount max_burn_amount{AmountFromValue(self.Arg<UniValue>("maxburnamount"))};
CMutableTransaction mtx;
if (!DecodeHexTx(mtx, request.params[0].get_str())) {
@@ -753,14 +753,8 @@ static RPCMethod getrawmempool()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- bool fVerbose = false;
- if (!request.params[0].isNull())
- fVerbose = request.params[0].get_bool();
-
- bool include_mempool_sequence = false;
- if (!request.params[1].isNull()) {
- include_mempool_sequence = request.params[1].get_bool();
- }
+ const bool fVerbose{self.Arg<bool>("verbose")};
+ const bool include_mempool_sequence{self.Arg<bool>("mempool_sequence")};
return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence);
},
@@ -792,9 +786,7 @@ static RPCMethod getmempoolancestors()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- bool fVerbose = false;
- if (!request.params[1].isNull())
- fVerbose = request.params[1].get_bool();
+ const bool fVerbose{self.Arg<bool>("verbose")};
auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
@@ -853,9 +845,7 @@ static RPCMethod getmempooldescendants()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- bool fVerbose = false;
- if (!request.params[1].isNull())
- fVerbose = request.params[1].get_bool();
+ const bool fVerbose{self.Arg<bool>("verbose")};
auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
@@ -1449,7 +1439,7 @@ static RPCMethod submitpackage()
}
// Burn sanity check is run with no context
- const CAmount max_burn_amount = request.params[2].isNull() ? 0 : AmountFromValue(request.params[2]);
+ const CAmount max_burn_amount{AmountFromValue(self.Arg<UniValue>("maxburnamount"))};
std::vector<CTransactionRef> txns;
txns.reserve(raw_transactions.size());
### src/rpc/mining.cpp
@@ -313,8 +313,8 @@ static RPCMethod generatetoaddress()
},
[](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
- const int num_blocks{request.params[0].getInt<int>()};
- const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt<int>()};
+ const int num_blocks{self.Arg<int>("nblocks")};
+ const uint64_t max_tries{self.Arg<uint64_t>("maxtries")};
CTxDestination destination = DecodeDestination(request.params[1].get_str());
if (!IsValidDestination(destination)) {
@@ -400,7 +400,7 @@ static RPCMethod generateblock()
}
}
- const bool process_new_block{request.params[2].isNull() ? true : request.params[2].get_bool()};
+ const bool process_new_block{self.Arg<bool>("submit")};
CBlock block;
ChainstateManager& chainman = EnsureChainman(node);
### src/rpc/net.cpp
@@ -850,11 +850,8 @@ static RPCMethod setban()
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
}
- int64_t banTime = 0; //use standard bantime if not specified
- if (!request.params[2].isNull())
- banTime = request.params[2].getInt<int64_t>();
-
- const bool absolute{request.params[3].isNull() ? false : request.params[3].get_bool()};
+ const int64_t banTime{help.Arg<int64_t>("bantime")};
+ const bool absolute{help.Arg<bool>("absolute")};
if (absolute && banTime < GetTime()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Absolute timestamp is in the past");
@@ -1008,7 +1005,7 @@ static RPCMethod getnodeaddresses()
NodeContext& node = EnsureAnyNodeContext(request.context);
const CConnman& connman = EnsureConnman(node);
- const int count{request.params[0].isNull() ? 1 : request.params[0].getInt<int>()};
+ const int count{self.Arg<int>("count")};
if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
const std::optional<Network> network{request.params[1].isNull() ? std::nullopt : std::optional<Network>{ParseNetwork(request.params[1].get_str())}};
@@ -1060,7 +1057,7 @@ static RPCMethod addpeeraddress()
const std::string& addr_string{request.params[0].get_str()};
const auto port{request.params[1].getInt<uint16_t>()};
- const bool tried{request.params[2].isNull() ? false : request.params[2].get_bool()};
+ const bool tried{self.Arg<bool>("tried")};
UniValue obj(UniValue::VOBJ);
std::optional<CNetAddr> net_addr{LookupHost(addr_string, false)};
### src/rpc/rawtransaction.cpp
@@ -1693,7 +1693,7 @@ static RPCMethod finalizepsbt()
}
PartiallySignedTransaction psbtx = *psbt_res;
- bool extract = request.params[1].isNull() || (!request.params[1].isNull() && request.params[1].get_bool());
+ const bool extract{self.Arg<bool>("extract")};
CMutableTransaction mtx;
bool complete = FinalizeAndExtractPSBT(psbtx, mtx);
@@ -1747,14 +1747,11 @@ static RPCMethod createpsbt()
CMutableTransaction rawTx = ConstructTransaction(request.params[0], request.params[1], request.params[2], rbf, self.Arg<uint32_t>("version"));
// Make a blank psbt
- uint32_t psbt_version = 2;
- if (!request.params[5].isNull()) {
- psbt_version = request.params[5].getInt<uint32_t>();
- }
+ const uint32_t psbt_version{self.Arg<uint32_t>("psbt_version")};
if (psbt_version != 2 && psbt_version != 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "The PSBT version can only be 2 or 0");
}
- PartiallySignedTransaction psbtx(rawTx, psbt_version);
+ PartiallySignedTransaction psbtx{rawTx, psbt_version};
// Serialize the PSBT
DataStream ssTx{};
@@ -1797,7 +1794,7 @@ static RPCMethod converttopsbt()
{
// parse hex string from parameter
CMutableTransaction tx;
- bool permitsigdata = request.params[1].isNull() ? false : request.params[1].get_bool();
+ const bool permitsigdata{self.Arg<bool>("permitsigdata")};
bool witness_specified = !request.params[2].isNull();
bool iswitness = witness_specified ? request.params[2].get_bool() : false;
const bool try_witness = witness_specified ? iswitness : true;
@@ -1816,14 +1813,11 @@ static RPCMethod converttopsbt()
}
// Make a blank psbt
- uint32_t psbt_version = 2;
- if (!request.params[3].isNull()) {
- psbt_version = request.params[3].getInt<uint32_t>();
- }
+ const uint32_t psbt_version{self.Arg<uint32_t>("psbt_version")};
if (psbt_version != 2 && psbt_version != 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "The PSBT version can only be 2 or 0");
}
- PartiallySignedTransaction psbtx(tx, psbt_version);
+ PartiallySignedTransaction psbtx{tx, psbt_version};
// Serialize the PSBT
DataStream ssTx{};
@@ -2123,8 +2117,8 @@ RPCMethod descriptorprocesspsbt()
}
std::optional<int> sighash_type = ParseSighashString(request.params[2]);
- bool bip32derivs = request.params[3].isNull() ? true : request.params[3].get_bool();
- bool finalize = request.params[4].isNull() ? true : request.params[4].get_bool();
+ const bool bip32derivs{self.Arg<bool>("bip32derivs")};
+ const bool finalize{self.Arg<bool>("finalize")};
const PartiallySignedTransaction& psbtx = ProcessPSBT(
request.params[0].get_str(),
### src/rpc/util.cpp
@@ -30,8 +30,8 @@
#include <util/translation.h>
#include <algorithm>
-#include <iterator>
#include <memory>
+#include <ranges>
#include <set>
#include <span>
#include <string_view>
@@ -735,7 +735,9 @@ TMPL_INST(nullptr, std::optional<std::string_view>, maybe_arg ? std::optional<st
// Required arg or optional arg with default value.
TMPL_INST(CheckRequiredOrDefault, const UniValue&, *CHECK_NONFATAL(maybe_arg););
TMPL_INST(CheckRequiredOrDefault, bool, CHECK_NONFATAL(maybe_arg)->get_bool(););
+TMPL_INST(CheckRequiredOrDefault, double, CHECK_NONFATAL(maybe_arg)->get_real(););
TMPL_INST(CheckRequiredOrDefault, int, CHECK_NONFATAL(maybe_arg)->getInt<int>(););
+TMPL_INST(CheckRequiredOrDefault, int64_t, CHECK_NONFATAL(maybe_arg)->getInt<int64_t>(););
TMPL_INST(CheckRequiredOrDefault, uint64_t, CHECK_NONFATAL(maybe_arg)->getInt<uint64_t>(););
TMPL_INST(CheckRequiredOrDefault, uint32_t, CHECK_NONFATAL(maybe_arg)->getInt<uint32_t>(););
TMPL_INST(CheckRequiredOrDefault, std::string_view, CHECK_NONFATAL(maybe_arg)->get_str(););
@@ -769,9 +771,8 @@ std::vector<std::pair<std::string, bool>> RPCMethod::GetArgNames() const
size_t RPCMethod::GetParamIndex(std::string_view key) const
{
- auto it{std::find_if(
- m_args.begin(), m_args.end(), [&key](const auto& arg) { return arg.GetName() == key;}
- )};
+ // Use only the first name, so that callers are uniform and legacy aliases can be removed.
+ auto it{std::ranges::find_if(m_args, [&key](const auto& arg) { return arg.GetFirstName() == key; })};
CHECK_NONFATAL(it != m_args.end()); // TODO: ideally this is checked at compile time
return std::distance(m_args.begin(), it);
### src/rpc/util.h
@@ -462,6 +462,7 @@ class RPCMethod
*
* The instantiation of this helper for type R must match the corresponding RPCArg::Type.
*
+ * @param key The first name of the argument. Aliases are not supported.
* @return The value of the RPC argument (or the default value) cast to type R.
*
* @see MaybeArg for handling optional arguments without default values.
@@ -492,6 +493,7 @@ class RPCMethod
*
* The instantiation of this helper for type R must match the corresponding RPCArg::Type.
*
+ * @param key The first name of the argument. Aliases are not supported.
* @return For trivially copyable types, a std::optional<R> is returned.
* For other types, a R* pointer to the argument is returned. If the
* argument is not provided, std::nullopt or a null pointer is returned.
@@ -533,7 +535,7 @@ class RPCMethod
mutable const JSONRPCRequest* m_req{nullptr}; // A pointer to the request for the duration of m_fun()
template <typename R>
R ArgValue(size_t i) const;
- //! Return positional index of a parameter using its name as key.
+ //! Return positional index of a parameter using its first name as key.
size_t GetParamIndex(std::string_view key) const;
};
### src/test/rpc_tests.cpp
@@ -647,10 +647,10 @@ BOOST_AUTO_TEST_CASE(rpc_arg_helper)
// Default arg
{"def_uint64_t", RPCArg::Type::NUM, RPCArg::Default{DEFAULT_UINT64_T}, ""},
{"def_string", RPCArg::Type::STR, RPCArg::Default{DEFAULT_STRING}, ""},
- {"def_bool", RPCArg::Type::BOOL, RPCArg::Default{DEFAULT_BOOL}, ""},
+ {"def_bool|legacy_def_bool", RPCArg::Type::BOOL, RPCArg::Default{DEFAULT_BOOL}, ""},
// Optional arg without default
{"opt_double", RPCArg::Type::NUM, RPCArg::Optional::OMITTED, ""},
- {"opt_string", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""}
+ {"opt_string", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""},
};
//! Check that `self.Arg` returns the same value as the `request.params` accessors
@@ -660,6 +660,10 @@ BOOST_AUTO_TEST_CASE(rpc_arg_helper)
BOOST_CHECK_EQUAL(self.Arg<uint64_t>("def_uint64_t"), request.params[2].isNull() ? DEFAULT_UINT64_T : request.params[2].getInt<uint64_t>());
BOOST_CHECK_EQUAL(self.Arg<std::string_view>("def_string"), request.params[3].isNull() ? DEFAULT_STRING : request.params[3].get_str());
BOOST_CHECK_EQUAL(self.Arg<bool>("def_bool"), request.params[4].isNull() ? DEFAULT_BOOL : request.params[4].get_bool());
+ {
+ test_only_CheckFailuresAreExceptionsNotAborts mock_checks{};
+ BOOST_CHECK_EXCEPTION(self.Arg<bool>("legacy_def_bool"), NonFatalCheckError, HasReason{"Internal bug detected:"});
+ }
if (!request.params[5].isNull()) {
BOOST_CHECK_EQUAL(self.MaybeArg<double>("opt_double").value(), request.params[5].get_real());
} else {
### src/wallet/rpc/addresses.cpp
@@ -48,7 +48,7 @@ RPCMethod getnewaddress()
}
// Parse the label first so we don't generate a key if there's an error
- const std::string label{LabelFromValue(request.params[0])};
+ const std::string label{LabelFromValue(self.Arg<UniValue>("label"))};
OutputType output_type = pwallet->m_default_address_type;
if (!request.params[1].isNull()) {
### src/wallet/rpc/backup.cpp
@@ -345,7 +345,7 @@ RPCMethod listdescriptors()
const std::shared_ptr<const CWallet> wallet = GetWalletForJSONRPCRequest(request);
if (!wallet) return UniValue::VNULL;
- const bool priv = !request.params[0].isNull() && request.params[0].get_bool();
+ const bool priv{self.Arg<bool>("private")};
if (wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && priv) {
throw JSONRPCError(RPC_WALLET_ERROR, "Can't get private descriptor string for watch-only wallets");
}
### src/wallet/rpc/coins.cpp
@@ -269,7 +269,7 @@ RPCMethod lockunspent()
bool fUnlock = request.params[0].get_bool();
- const bool persistent{request.params[2].isNull() ? false : request.params[2].get_bool()};
+ const bool persistent{self.Arg<bool>("persistent")};
if (request.params[1].isNull()) {
if (fUnlock) {
@@ -523,15 +523,8 @@ RPCMethod listunspent()
const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return UniValue::VNULL;
- int nMinDepth = 1;
- if (!request.params[0].isNull()) {
- nMinDepth = request.params[0].getInt<int>();
- }
-
- int nMaxDepth = 9999999;
- if (!request.params[1].isNull()) {
- nMaxDepth = request.params[1].getInt<int>();
- }
+ const int nMinDepth{self.Arg<int>("minconf")};
+ const int nMaxDepth{self.Arg<int>("maxconf")};
std::set<CTxDestination> destinations;
if (!request.params[2].isNull()) {
@@ -548,10 +541,7 @@ RPCMethod listunspent()
}
}
- bool include_unsafe = true;
- if (!request.params[3].isNull()) {
- include_unsafe = request.params[3].get_bool();
- }
+ const bool include_unsafe{self.Arg<bool>("include_unsafe")};
CoinFilterParams filter_coins;
filter_coins.min_amount = 0;
### src/wallet/rpc/spend.cpp
@@ -344,12 +344,12 @@ RPCMethod sendtoaddress()
address_amounts.pushKV(address, request.params[1]);
std::set<int> sffo_set;
- if (!request.params[4].isNull() && request.params[4].get_bool()) {
+ if (self.Arg<bool>("subtractfeefromamount")) {
sffo_set.insert(0);
}
std::vector<CRecipient> recipients{CreateRecipients(ParseOutputs(address_amounts), sffo_set)};
- const bool verbose{request.params[10].isNull() ? false : request.params[10].get_bool()};
+ const bool verbose{self.Arg<bool>("verbose")};
return SendMoney(*pwallet, coin_control, recipients, comment, comment_to, verbose);
},
@@ -445,7 +445,7 @@ RPCMethod sendmany()
ParseOutputs(sendTo),
InterpretSubtractFeeFromOutputInstructions(request.params[4], sendTo.getKeys())
);
- const bool verbose{request.params[9].isNull() ? false : request.params[9].get_bool()};
+ const bool verbose{self.Arg<bool>("verbose")};
return SendMoney(*pwallet, coin_control, recipients, comment, /*comment_to=*/std::nullopt, verbose);
},
@@ -1170,7 +1170,7 @@ static RPCMethod bumpfee_helper(std::string method_name)
result.pushKV("txid", txid.GetHex());
} else {
- PartiallySignedTransaction psbtx(mtx, psbt_version);
+ PartiallySignedTransaction psbtx{mtx, psbt_version};
bool complete = false;
const auto err{pwallet->FillPSBT(psbtx, {.sign = false, .bip32_derivs = true}, complete)};
CHECK_NONFATAL(!err);
@@ -1687,9 +1687,9 @@ RPCMethod walletprocesspsbt()
std::optional<int> nHashType = ParseSighashString(request.params[2]);
// Fill transaction with our data and also sign
- bool sign = request.params[1].isNull() ? true : request.params[1].get_bool();
- bool bip32derivs = request.params[3].isNull() ? true : request.params[3].get_bool();
- bool finalize = request.params[4].isNull() ? true : request.params[4].get_bool();
+ const bool sign{self.Arg<bool>("sign")};
+ const bool bip32derivs{self.Arg<bool>("bip32derivs")};
+ const bool finalize{self.Arg<bool>("finalize")};
bool complete = true;
if (sign) EnsureWalletIsUnlocked(*pwallet);
@@ -1833,18 +1833,15 @@ RPCMethod walletcreatefundedpsbt()
auto txr = FundTransaction(wallet, rawTx, recipients, options, coin_control, /*override_min_fee=*/true);
// Make a blank psbt
- uint32_t psbt_version = 2;
- if (!request.params[6].isNull()) {
- psbt_version = request.params[6].getInt<int>();
- }
+ const uint32_t psbt_version{self.Arg<uint32_t>("psbt_version")};
if (psbt_version != 2 && psbt_version != 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "The PSBT version can only be 2 or 0");
}
PartiallySignedTransaction psbtx(CMutableTransaction(*txr.tx), psbt_version);
- // Fill transaction with out data but don't sign
- bool bip32derivs = request.params[4].isNull() ? true : request.params[4].get_bool();
+ // Fill transaction with our data but don't sign
+ const bool bip32derivs{self.Arg<bool>("bip32derivs")};
bool complete = true;
const auto err{wallet.FillPSBT(psbtx, {.sign = false, .bip32_derivs = bip32derivs}, complete)};
if (err) {
### src/wallet/rpc/transactions.cpp
@@ -247,7 +247,7 @@ RPCMethod listreceivedbyaddress()
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
- const bool include_immature_coinbase{request.params[4].isNull() ? false : request.params[4].get_bool()};
+ const bool include_immature_coinbase{self.Arg<bool>("include_immature_coinbase")};
LOCK(pwallet->cs_wallet);
@@ -292,7 +292,7 @@ RPCMethod listreceivedbylabel()
// the user could have gotten from another RPC command prior to now
pwallet->BlockUntilSyncedToCurrentChain();
- const bool include_immature_coinbase{request.params[3].isNull() ? false : request.params[3].get_bool()};
+ const bool include_immature_coinbase{self.Arg<bool>("include_immature_coinbase")};
LOCK(pwallet->cs_wallet);
@@ -752,7 +752,7 @@ RPCMethod listsinceblock()
std::optional<int> height; // Height of the specified block or the common ancestor, if the block provided was in a deactivated chain.
std::optional<int> altheight; // Height of the specified block, even if it's in a deactivated chain.
- int target_confirms = 1;
+ int target_confirms{self.Arg<int>("target_confirmations")};
uint256 blockId;
if (!request.params[0].isNull() && !request.params[0].get_str().empty()) {
@@ -764,16 +764,12 @@ RPCMethod listsinceblock()
}
}
- if (!request.params[1].isNull()) {
- target_confirms = request.params[1].getInt<int>();
-
- if (target_confirms < 1) {
- throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
- }
+ if (target_confirms < 1) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
}
- bool include_removed = (request.params[3].isNull() || request.params[3].get_bool());
- bool include_change = (!request.params[4].isNull() && request.params[4].get_bool());
+ const bool include_removed{self.Arg<bool>("include_removed")};
+ const bool include_change{self.Arg<bool>("include_change")};
// Only set it if 'label' was provided.
std::optional<std::string> filter_label;
@@ -893,7 +889,7 @@ RPCMethod gettransaction()
Txid hash{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
- bool verbose = request.params[2].isNull() ? false : request.params[2].get_bool();
+ const bool verbose{self.Arg<bool>("verbose")};
UniValue entry(UniValue::VOBJ);
auto it = pwallet->mapWallet.find(hash);
@@ -1002,7 +998,7 @@ RPCMethod rescanblockchain()
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
}
- int start_height = 0;
+ const int start_height{self.Arg<int>("start_height")};
std::optional<int> stop_height;
uint256 start_block;
@@ -1012,11 +1008,8 @@ RPCMethod rescanblockchain()
EnsureWalletIsUnlocked(*pwallet);
int tip_height = pwallet->GetLastBlockHeight();
- if (!request.params[0].isNull()) {
- start_height = request.params[0].getInt<int>();
- if (start_height < 0 || start_height > tip_height) {
- throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid start_height");
- }
+ if (start_height < 0 || start_height > tip_height) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid start_height");
}
if (!request.params[1].isNull()) {
### src/wallet/rpc/wallet.cpp
@@ -317,7 +317,7 @@ static RPCMethod setwalletflag()
if (!pwallet) return UniValue::VNULL;
std::string flag_str = request.params[0].get_str();
- bool value = request.params[1].isNull() || request.params[1].get_bool();
+ const bool value{self.Arg<bool>("value")};
if (!STRING_TO_WALLET_FLAG.contains(flag_str)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Unknown wallet flag: %s", flag_str));
@@ -388,11 +388,11 @@ static RPCMethod createwallet()
{
WalletContext& context = EnsureWalletContext(request.context);
uint64_t flags = 0;
- if (!request.params[1].isNull() && request.params[1].get_bool()) {
+ if (self.Arg<bool>("disable_private_keys")) {
flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS;
}
- if (!request.params[2].isNull() && request.params[2].get_bool()) {
+ if (self.Arg<bool>("blank")) {
flags |= WALLET_FLAG_BLANK_WALLET;
}
SecureString passphrase;
@@ -406,14 +406,14 @@ static RPCMethod createwallet()
}
}
- if (!request.params[4].isNull() && request.params[4].get_bool()) {
+ if (self.Arg<bool>("avoid_reuse")) {
flags |= WALLET_FLAG_AVOID_REUSE;
}
flags |= WALLET_FLAG_DESCRIPTORS;
if (!self.Arg<bool>("descriptors")) {
throw JSONRPCError(RPC_WALLET_ERROR, "descriptors argument must be set to \"true\"; it is no longer possible to create a legacy wallet.");
}
- if (!request.params[7].isNull() && request.params[7].get_bool()) {
+ if (self.Arg<bool>("external_signer")) {
#ifdef ENABLE_EXTERNAL_SIGNER
flags |= WALLET_FLAG_EXTERNAL_SIGNER;
#elseWhy this scored 21/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.