Skip to content

Commit

Permalink
rpc: disallow boolean verbosity in getorphantxs
Browse files Browse the repository at this point in the history
Updates ParseVerbosity() to support disallowing
boolean verbosity.  Removes boolean verbosity
for getorphantxs to encourage integer verbosity
usage
  • Loading branch information
tdb3 committed Oct 25, 2024
1 parent 63f5e6e commit 698f302
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
{
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down
6 changes: 4 additions & 2 deletions src/rpc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 698f302

Please sign in to comment.