Skip to content

Commit f915da7

Browse files
tdb3luke-jr
authored andcommitted
rpc: disallow boolean verbosity in getorphantxs
Updates ParseVerbosity() to support disallowing boolean verbosity. Removes boolean verbosity for getorphantxs to encourage integer verbosity usage Github-Pull: bitcoin#31043 Rebased-From: 698f302
1 parent 6703ee8 commit f915da7

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/rpc/client.cpp

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

src/rpc/mempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ static RPCHelpMan getorphantxs()
893893
"\nShows transactions in the tx orphanage.\n"
894894
"\nEXPERIMENTAL warning: this call may be changed in future releases.\n",
895895
{
896-
{"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",
896+
{"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",
897897
RPCArgOptions{.skip_type_check = true}},
898898
},
899899
{
@@ -928,7 +928,7 @@ static RPCHelpMan getorphantxs()
928928
PeerManager& peerman = EnsurePeerman(node);
929929
std::vector<TxOrphanage::OrphanTxBase> orphanage = peerman.GetOrphanTransactions();
930930

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

933933
UniValue ret(UniValue::VARR);
934934

src/rpc/util.cpp

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

83-
int ParseVerbosity(const UniValue& arg, int default_verbosity)
83+
int ParseVerbosity(const UniValue& arg, int default_verbosity, bool allow_bool)
8484
{
8585
if (!arg.isNull()) {
8686
if (arg.isBool()) {
87+
if (!allow_bool) {
88+
throw JSONRPCError(RPC_TYPE_ERROR, "Verbosity was boolean but only integer allowed");
89+
}
8790
return arg.get_bool(); // true = 1
8891
} else {
8992
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)