diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 4894cecfbda..d288ff0ef86 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -766,7 +766,7 @@ static RPCHelpMan getblock() { uint256 hash(ParseHashV(request.params[0], "blockhash")); - int verbosity{ParseVerbosity(request.params[1], /*default_verbosity=*/1)}; + int verbosity{ParseVerbosity(request.params[1], /*default_verbosity=*/1, /*allow_bool=*/true)}; const CBlockIndex* pblockindex; const CBlockIndex* tip; diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 601e4fa7bf5..43a7a218f66 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -255,7 +255,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getrawmempool", 0, "verbose" }, { "getrawmempool", 1, "mempool_sequence" }, { "getorphantxs", 0, "verbosity" }, - { "getorphantxs", 0, "verbose" }, { "estimatesmartfee", 0, "conf_target" }, { "estimaterawfee", 0, "conf_target" }, { "estimaterawfee", 1, "threshold" }, diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp index 7bdbd35ec42..b26d94b0825 100644 --- a/src/rpc/mempool.cpp +++ b/src/rpc/mempool.cpp @@ -854,7 +854,7 @@ static RPCHelpMan getorphantxs() "\nShows transactions in the tx orphanage.\n" "\nEXPERIMENTAL warning: this call may be changed in future releases.\n", { - {"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{0}, "0 for an array of txids (may contain duplicates), 1 for an array of objects with tx details, and 2 for details from (1) and tx hex", + {"verbosity", RPCArg::Type::NUM, RPCArg::Default{0}, "0 for an array of txids (may contain duplicates), 1 for an array of objects with tx details, and 2 for details from (1) and tx hex", RPCArgOptions{.skip_type_check = true}}, }, { @@ -889,7 +889,7 @@ static RPCHelpMan getorphantxs() PeerManager& peerman = EnsurePeerman(node); std::vector orphanage = peerman.GetOrphanTransactions(); - int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0)}; + int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0, /*allow_bool*/false)}; UniValue ret(UniValue::VARR); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 65e6e40b0dc..db35421688e 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -338,7 +338,7 @@ static RPCHelpMan getrawtransaction() throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "The genesis block coinbase is not considered an ordinary transaction and cannot be retrieved"); } - int verbosity{ParseVerbosity(request.params[1], /*default_verbosity=*/0)}; + int verbosity{ParseVerbosity(request.params[1], /*default_verbosity=*/0, /*allow_bool=*/true)}; if (!request.params[2].isNull()) { LOCK(cs_main); diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index d71d7d737b0..81461f91ad6 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -81,10 +81,13 @@ void RPCTypeCheckObj(const UniValue& o, } } -int ParseVerbosity(const UniValue& arg, int default_verbosity) +int ParseVerbosity(const UniValue& arg, int default_verbosity, bool allow_bool) { if (!arg.isNull()) { if (arg.isBool()) { + if (!allow_bool) { + throw JSONRPCError(RPC_TYPE_ERROR, "Verbosity was boolean but only integer allowed"); + } return arg.get_bool(); // true = 1 } else { return arg.getInt(); diff --git a/src/rpc/util.h b/src/rpc/util.h index b8e67597688..f7268f00012 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -103,11 +103,13 @@ std::vector ParseHexO(const UniValue& o, std::string_view strKey) /** * Parses verbosity from provided UniValue. * - * @param[in] arg The verbosity argument as a bool (true) or int (0, 1, 2,...) + * @param[in] arg The verbosity argument as an int (0, 1, 2,...) or bool if allow_bool is set to true * @param[in] default_verbosity The value to return if verbosity argument is null + * @param[in] allow_bool If true, allows arg to be a bool and parses it * @returns An integer describing the verbosity level (e.g. 0, 1, 2, etc.) + * @throws JSONRPCError if allow_bool is false but arg provided is boolean */ -int ParseVerbosity(const UniValue& arg, int default_verbosity); +int ParseVerbosity(const UniValue& arg, int default_verbosity, bool allow_bool); /** * Validate and return a CAmount from a UniValue number or string.