Skip to content

Commit fa5c5cd

Browse files
author
MarcoFalke
committed
rpc: Switch touched RPCs to IsValidNumArgs
1 parent 653b2b4 commit fa5c5cd

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,7 @@ static UniValue createrawtransaction(const JSONRPCRequest& request)
431431

432432
static UniValue decoderawtransaction(const JSONRPCRequest& request)
433433
{
434-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
435-
throw std::runtime_error(
436-
RPCHelpMan{"decoderawtransaction",
434+
const RPCHelpMan help{"decoderawtransaction",
437435
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
438436
{
439437
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"},
@@ -485,7 +483,11 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request)
485483
HelpExampleCli("decoderawtransaction", "\"hexstring\"")
486484
+ HelpExampleRpc("decoderawtransaction", "\"hexstring\"")
487485
},
488-
}.ToString());
486+
};
487+
488+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
489+
throw std::runtime_error(help.ToString());
490+
}
489491

490492
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL});
491493

@@ -1415,9 +1417,7 @@ UniValue createpsbt(const JSONRPCRequest& request)
14151417

14161418
UniValue converttopsbt(const JSONRPCRequest& request)
14171419
{
1418-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
1419-
throw std::runtime_error(
1420-
RPCHelpMan{"converttopsbt",
1420+
const RPCHelpMan help{"converttopsbt",
14211421
"\nConverts a network serialized transaction to a PSBT. This should be used only with createrawtransaction and fundrawtransaction\n"
14221422
"createpsbt and walletcreatefundedpsbt should be used for new applications.\n",
14231423
{
@@ -1438,7 +1438,11 @@ UniValue converttopsbt(const JSONRPCRequest& request)
14381438
"\nConvert the transaction to a PSBT\n"
14391439
+ HelpExampleCli("converttopsbt", "\"rawtransaction\"")
14401440
},
1441-
}.ToString());
1441+
};
1442+
1443+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
1444+
throw std::runtime_error(help.ToString());
1445+
}
14421446

14431447

14441448
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL}, true);

src/wallet/rpcwallet.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,9 +2991,7 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request)
29912991
return NullUniValue;
29922992
}
29932993

2994-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
2995-
throw std::runtime_error(
2996-
RPCHelpMan{"fundrawtransaction",
2994+
const RPCHelpMan help{"fundrawtransaction",
29972995
"\nAdd inputs to a transaction until it has enough in value to meet its out value.\n"
29982996
"This will not modify existing inputs, and will add at most one change output to the outputs.\n"
29992997
"No existing outputs will be modified unless \"subtractFeeFromOutputs\" is specified.\n"
@@ -3052,7 +3050,11 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request)
30523050
"\nSend the transaction\n"
30533051
+ HelpExampleCli("sendrawtransaction", "\"signedtransactionhex\"")
30543052
},
3055-
}.ToString());
3053+
};
3054+
3055+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
3056+
throw std::runtime_error(help.ToString());
3057+
}
30563058

30573059
RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType(), UniValue::VBOOL});
30583060

0 commit comments

Comments
 (0)