rpc: disallow boolean verbosity in getorphantxs

Updates ParseVerbosity() to support disallowing
boolean verbosity.  Removes boolean verbosity
for getorphantxs to encourage integer verbosity
usage
pull/31043/head
tdb3 2 weeks ago
parent 63f5e6ec79
commit 698f302df8
No known key found for this signature in database

@ -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;

@ -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" },

@ -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<TxOrphanage::OrphanTxBase> 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);

@ -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);

@ -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<int>();

@ -103,11 +103,13 @@ std::vector<unsigned char> 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.

Loading…
Cancel
Save