Skip to content

Commit 71d068d

Browse files
author
MarcoFalke
committed
Merge #18531: rpc: remove deprecated CRPCCommand constructor
faaf9c5 remove CRPCCommand constructor that takes rpcfn_type function pointer (MarcoFalke) fa19bb2 remove dead rpc code (MarcoFalke) Pull request description: Remove the CRPCCommand arguments, now that they are asserted to be equal and thus redundant ### Future work > Here or follow up, makes sense to also assert type of returned UniValue? Sure, but let's not get ahead of ourselves. I am going to submit any further works as follow-ups, including: * Removing all python regex linters on the args, now that RPCMan can be used to generate any output, including the cli.cpp table * Auto-formatting and sanity checking the RPCExamples with RPCMan * Checking passed-in json in self-check. Removing redundant checks * Checking returned json against documentation to avoid regressions or false documentation * Compile the RPC documentation at compile-time to ensure it doesn't change at runtime and is completely static ### Bugs found * The assert identified issue #18607 * The changes itself fixed bug #19250 ACKs for top commit: fjahr: tested ACK faaf9c5 promag: Tested ACK faaf9c5. ryanofsky: Code review ACK faaf9c5. Two obviously good simplifications. Tree-SHA512: 5de3b440f7b2ed2c3e86655d4f0e2e5df9c67e8ce3c7817d5ea5311d1a38690f2f3e28fab41aad6936be9fc884326d037e5f19e85d4d2fe281474dada13911ee
2 parents 9ab9665 + faaf9c5 commit 71d068d

File tree

6 files changed

+20
-51
lines changed

6 files changed

+20
-51
lines changed

src/qt/test/rpcnestedtests.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,26 @@
1414
#include <QDir>
1515
#include <QtGlobal>
1616

17-
static UniValue rpcNestedTest_rpc(const JSONRPCRequest& request)
17+
static RPCHelpMan rpcNestedTest_rpc()
1818
{
19-
if (request.fHelp) {
20-
return "help message";
21-
}
22-
return request.params.write(0, 0);
19+
return RPCHelpMan{
20+
"rpcNestedTest",
21+
"echo the passed string(s)",
22+
{
23+
{"arg1", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""},
24+
{"arg2", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""},
25+
{"arg3", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""},
26+
},
27+
{},
28+
RPCExamples{""},
29+
[](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
30+
return request.params.write(0, 0);
31+
},
32+
};
2333
}
2434

25-
static const CRPCCommand vRPCCommands[] =
26-
{
27-
{ "test", "rpcNestedTest", &rpcNestedTest_rpc, {} },
35+
static const CRPCCommand vRPCCommands[] = {
36+
{"test", "rpcNestedTest", &rpcNestedTest_rpc, {"arg1", "arg2", "arg3"}},
2837
};
2938

3039
void RPCNestedTests::rpcNestedTests()

src/rpc/mining.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,7 @@ static RPCHelpMan generatetodescriptor()
242242
static RPCHelpMan generate()
243243
{
244244
return RPCHelpMan{"generate", "has been replaced by the -generate cli option. Refer to -help for more information.", {}, {}, RPCExamples{""}, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
245-
246-
if (request.fHelp) {
247-
throw std::runtime_error(self.ToString());
248-
} else {
249245
throw JSONRPCError(RPC_METHOD_NOT_FOUND, self.ToString());
250-
}
251246
}};
252247
}
253248

src/rpc/misc.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,6 @@ static RPCHelpMan echo(const std::string& name)
624624
RPCExamples{""},
625625
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
626626
{
627-
if (request.fHelp) throw std::runtime_error(self.ToString());
628-
629627
if (request.params[9].isStr()) {
630628
CHECK_NONFATAL(request.params[9].get_str() != "trigger_internal_bug");
631629
}

src/rpc/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ static RPCHelpMan addnode()
288288
std::string strCommand;
289289
if (!request.params[1].isNull())
290290
strCommand = request.params[1].get_str();
291-
if (request.fHelp || request.params.size() != 2 ||
292-
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
291+
if (strCommand != "onetry" && strCommand != "add" && strCommand != "remove") {
293292
throw std::runtime_error(
294293
self.ToString());
294+
}
295295

296296
NodeContext& node = EnsureNodeContext(request.context);
297297
if(!node.connman)
@@ -628,7 +628,7 @@ static RPCHelpMan setban()
628628
std::string strCommand;
629629
if (!request.params[1].isNull())
630630
strCommand = request.params[1].get_str();
631-
if (request.fHelp || !help.IsValidNumArgs(request.params.size()) || (strCommand != "add" && strCommand != "remove")) {
631+
if (strCommand != "add" && strCommand != "remove") {
632632
throw std::runtime_error(help.ToString());
633633
}
634634
NodeContext& node = EnsureNodeContext(request.context);

src/rpc/server.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface);
8585
*/
8686
void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds);
8787

88-
typedef UniValue(*rpcfn_type)(const JSONRPCRequest& jsonRequest);
8988
typedef RPCHelpMan (*RpcMethodFnType)();
9089

9190
class CRPCCommand
@@ -116,14 +115,6 @@ class CRPCCommand
116115
CHECK_NONFATAL(fn().GetArgNames() == args_in);
117116
}
118117

119-
//! Simplified constructor taking plain rpcfn_type function pointer.
120-
CRPCCommand(const char* category, const char* name, rpcfn_type fn, std::initializer_list<const char*> args)
121-
: CRPCCommand(category, name,
122-
[fn](const JSONRPCRequest& request, UniValue& result, bool) { result = fn(request); return true; },
123-
{args.begin(), args.end()}, intptr_t(fn))
124-
{
125-
}
126-
127118
std::string category;
128119
std::string name;
129120
Actor actor;

test/lint/lint-rpc-help.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)