Skip to content

Commit 698f302

Browse files
committed
rpc: disallow boolean verbosity in getorphantxs
Updates ParseVerbosity() to support disallowing boolean verbosity. Removes boolean verbosity for getorphantxs to encourage integer verbosity usage
1 parent 63f5e6e commit 698f302

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

src/rpc/blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ static RPCHelpMan getblock()
766766
{
767767
uint256 hash(ParseHashV(request.params[0], "blockhash"));
768768

769-
int verbosity{ParseVerbosity(request.params[1], /*default_verbosity=*/1)};
769+
int verbosity{ParseVerbosity(request.params[1], /*default_verbosity=*/1, /*allow_bool=*/true)};
770770

771771
const CBlockIndex* pblockindex;
772772
const CBlockIndex* tip;

src/rpc/client.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
255255
{ "getrawmempool", 0, "verbose" },
256256
{ "getrawmempool", 1, "mempool_sequence" },
257257
{ "getorphantxs", 0, "verbosity" },
258-
{ "getorphantxs", 0, "verbose" },
259258
{ "estimatesmartfee", 0, "conf_target" },
260259
{ "estimaterawfee", 0, "conf_target" },
261260
{ "estimaterawfee", 1, "threshold" },

src/rpc/mempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ static RPCHelpMan getorphantxs()
854854
"\nShows transactions in the tx orphanage.\n"
855855
"\nEXPERIMENTAL warning: this call may be changed in future releases.\n",
856856
{
857-
{"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",
857+
{"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",
858858
RPCArgOptions{.skip_type_check = true}},
859859
},
860860
{
@@ -889,7 +889,7 @@ static RPCHelpMan getorphantxs()
889889
PeerManager& peerman = EnsurePeerman(node);
890890
std::vector<TxOrphanage::OrphanTxBase> orphanage = peerman.GetOrphanTransactions();
891891

892-
int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0)};
892+
int verbosity{ParseVerbosity(request.params[0], /*default_verbosity=*/0, /*allow_bool*/false)};
893893

894894
UniValue ret(UniValue::VARR);
895895

src/rpc/rawtransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static RPCHelpMan getrawtransaction()
338338
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "The genesis block coinbase is not considered an ordinary transaction and cannot be retrieved");
339339
}
340340

341-
int verbosity{ParseVerbosity(request.params[1], /*default_verbosity=*/0)};
341+
int verbosity{ParseVerbosity(request.params[1], /*default_verbosity=*/0, /*allow_bool=*/true)};
342342

343343
if (!request.params[2].isNull()) {
344344
LOCK(cs_main);

src/rpc/util.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ void RPCTypeCheckObj(const UniValue& o,
8181
}
8282
}
8383

84-
int ParseVerbosity(const UniValue& arg, int default_verbosity)
84+
int ParseVerbosity(const UniValue& arg, int default_verbosity, bool allow_bool)
8585
{
8686
if (!arg.isNull()) {
8787
if (arg.isBool()) {
88+
if (!allow_bool) {
89+
throw JSONRPCError(RPC_TYPE_ERROR, "Verbosity was boolean but only integer allowed");
90+
}
8891
return arg.get_bool(); // true = 1
8992
} else {
9093
return arg.getInt<int>();

src/rpc/util.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ std::vector<unsigned char> ParseHexO(const UniValue& o, std::string_view strKey)
103103
/**
104104
* Parses verbosity from provided UniValue.
105105
*
106-
* @param[in] arg The verbosity argument as a bool (true) or int (0, 1, 2,...)
106+
* @param[in] arg The verbosity argument as an int (0, 1, 2,...) or bool if allow_bool is set to true
107107
* @param[in] default_verbosity The value to return if verbosity argument is null
108+
* @param[in] allow_bool If true, allows arg to be a bool and parses it
108109
* @returns An integer describing the verbosity level (e.g. 0, 1, 2, etc.)
110+
* @throws JSONRPCError if allow_bool is false but arg provided is boolean
109111
*/
110-
int ParseVerbosity(const UniValue& arg, int default_verbosity);
112+
int ParseVerbosity(const UniValue& arg, int default_verbosity, bool allow_bool);
111113

112114
/**
113115
* Validate and return a CAmount from a UniValue number or string.

0 commit comments

Comments
 (0)