Skip to content

Commit fa965e0

Browse files
author
MarcoFalke
committed
rpc: Use IsValidNumArgs over hardcoded size checks
1 parent c033c4b commit fa965e0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
10331033

10341034
static UniValue sendrawtransaction(const JSONRPCRequest& request)
10351035
{
1036-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
1037-
throw std::runtime_error(
1038-
RPCHelpMan{"sendrawtransaction",
1036+
const RPCHelpMan help{"sendrawtransaction",
10391037
"\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
10401038
"\nAlso see createrawtransaction and signrawtransactionwithkey calls.\n",
10411039
{
@@ -1055,7 +1053,11 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
10551053
"\nAs a JSON-RPC call\n"
10561054
+ HelpExampleRpc("sendrawtransaction", "\"signedhex\"")
10571055
},
1058-
}.ToString());
1056+
};
1057+
1058+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
1059+
throw std::runtime_error(help.ToString());
1060+
}
10591061

10601062
RPCTypeCheck(request.params, {
10611063
UniValue::VSTR,
@@ -1095,9 +1097,7 @@ static UniValue sendrawtransaction(const JSONRPCRequest& request)
10951097

10961098
static UniValue testmempoolaccept(const JSONRPCRequest& request)
10971099
{
1098-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
1099-
throw std::runtime_error(
1100-
RPCHelpMan{"testmempoolaccept",
1100+
const RPCHelpMan help{"testmempoolaccept",
11011101
"\nReturns result of mempool acceptance tests indicating if raw transaction (serialized, hex-encoded) would be accepted by mempool.\n"
11021102
"\nThis checks if the transaction violates the consensus or policy rules.\n"
11031103
"\nSee sendrawtransaction call.\n",
@@ -1130,7 +1130,10 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
11301130
"\nAs a JSON-RPC call\n"
11311131
+ HelpExampleRpc("testmempoolaccept", "[\"signedhex\"]")
11321132
},
1133-
}.ToString());
1133+
};
1134+
1135+
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) {
1136+
throw std::runtime_error(help.ToString());
11341137
}
11351138

11361139
RPCTypeCheck(request.params, {

0 commit comments

Comments
 (0)