mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-08 09:21:06 +02:00
Merge #18531: rpc: remove deprecated CRPCCommand constructor
faaf9c58e4
remove CRPCCommand constructor that takes rpcfn_type function pointer (MarcoFalke)fa19bb2cd8
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 ACKfaaf9c58e4
promag: Tested ACKfaaf9c58e4
. ryanofsky: Code review ACKfaaf9c58e4
. Two obviously good simplifications. Tree-SHA512: 5de3b440f7b2ed2c3e86655d4f0e2e5df9c67e8ce3c7817d5ea5311d1a38690f2f3e28fab41aad6936be9fc884326d037e5f19e85d4d2fe281474dada13911ee
This commit is contained in:
@ -14,17 +14,26 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
static UniValue rpcNestedTest_rpc(const JSONRPCRequest& request)
|
static RPCHelpMan rpcNestedTest_rpc()
|
||||||
{
|
{
|
||||||
if (request.fHelp) {
|
return RPCHelpMan{
|
||||||
return "help message";
|
"rpcNestedTest",
|
||||||
}
|
"echo the passed string(s)",
|
||||||
return request.params.write(0, 0);
|
{
|
||||||
|
{"arg1", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""},
|
||||||
|
{"arg2", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""},
|
||||||
|
{"arg3", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""},
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
RPCExamples{""},
|
||||||
|
[](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
|
||||||
|
return request.params.write(0, 0);
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static const CRPCCommand vRPCCommands[] =
|
static const CRPCCommand vRPCCommands[] = {
|
||||||
{
|
{"test", "rpcNestedTest", &rpcNestedTest_rpc, {"arg1", "arg2", "arg3"}},
|
||||||
{ "test", "rpcNestedTest", &rpcNestedTest_rpc, {} },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void RPCNestedTests::rpcNestedTests()
|
void RPCNestedTests::rpcNestedTests()
|
||||||
|
@ -242,12 +242,7 @@ static RPCHelpMan generatetodescriptor()
|
|||||||
static RPCHelpMan generate()
|
static RPCHelpMan generate()
|
||||||
{
|
{
|
||||||
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 {
|
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 {
|
||||||
|
|
||||||
if (request.fHelp) {
|
|
||||||
throw std::runtime_error(self.ToString());
|
|
||||||
} else {
|
|
||||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, self.ToString());
|
throw JSONRPCError(RPC_METHOD_NOT_FOUND, self.ToString());
|
||||||
}
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,8 +624,6 @@ static RPCHelpMan echo(const std::string& name)
|
|||||||
RPCExamples{""},
|
RPCExamples{""},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
if (request.fHelp) throw std::runtime_error(self.ToString());
|
|
||||||
|
|
||||||
if (request.params[9].isStr()) {
|
if (request.params[9].isStr()) {
|
||||||
CHECK_NONFATAL(request.params[9].get_str() != "trigger_internal_bug");
|
CHECK_NONFATAL(request.params[9].get_str() != "trigger_internal_bug");
|
||||||
}
|
}
|
||||||
|
@ -288,10 +288,10 @@ static RPCHelpMan addnode()
|
|||||||
std::string strCommand;
|
std::string strCommand;
|
||||||
if (!request.params[1].isNull())
|
if (!request.params[1].isNull())
|
||||||
strCommand = request.params[1].get_str();
|
strCommand = request.params[1].get_str();
|
||||||
if (request.fHelp || request.params.size() != 2 ||
|
if (strCommand != "onetry" && strCommand != "add" && strCommand != "remove") {
|
||||||
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
|
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
self.ToString());
|
self.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
NodeContext& node = EnsureNodeContext(request.context);
|
NodeContext& node = EnsureNodeContext(request.context);
|
||||||
if(!node.connman)
|
if(!node.connman)
|
||||||
@ -628,7 +628,7 @@ static RPCHelpMan setban()
|
|||||||
std::string strCommand;
|
std::string strCommand;
|
||||||
if (!request.params[1].isNull())
|
if (!request.params[1].isNull())
|
||||||
strCommand = request.params[1].get_str();
|
strCommand = request.params[1].get_str();
|
||||||
if (request.fHelp || !help.IsValidNumArgs(request.params.size()) || (strCommand != "add" && strCommand != "remove")) {
|
if (strCommand != "add" && strCommand != "remove") {
|
||||||
throw std::runtime_error(help.ToString());
|
throw std::runtime_error(help.ToString());
|
||||||
}
|
}
|
||||||
NodeContext& node = EnsureNodeContext(request.context);
|
NodeContext& node = EnsureNodeContext(request.context);
|
||||||
|
@ -85,7 +85,6 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface);
|
|||||||
*/
|
*/
|
||||||
void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds);
|
void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds);
|
||||||
|
|
||||||
typedef UniValue(*rpcfn_type)(const JSONRPCRequest& jsonRequest);
|
|
||||||
typedef RPCHelpMan (*RpcMethodFnType)();
|
typedef RPCHelpMan (*RpcMethodFnType)();
|
||||||
|
|
||||||
class CRPCCommand
|
class CRPCCommand
|
||||||
@ -116,14 +115,6 @@ public:
|
|||||||
CHECK_NONFATAL(fn().GetArgNames() == args_in);
|
CHECK_NONFATAL(fn().GetArgNames() == args_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Simplified constructor taking plain rpcfn_type function pointer.
|
|
||||||
CRPCCommand(const char* category, const char* name, rpcfn_type fn, std::initializer_list<const char*> args)
|
|
||||||
: CRPCCommand(category, name,
|
|
||||||
[fn](const JSONRPCRequest& request, UniValue& result, bool) { result = fn(request); return true; },
|
|
||||||
{args.begin(), args.end()}, intptr_t(fn))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string category;
|
std::string category;
|
||||||
std::string name;
|
std::string name;
|
||||||
Actor actor;
|
Actor actor;
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#
|
|
||||||
# Copyright (c) 2018 The Bitcoin Core developers
|
|
||||||
# Distributed under the MIT software license, see the accompanying
|
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
#
|
|
||||||
# Check that all RPC help texts are generated by RPCHelpMan.
|
|
||||||
|
|
||||||
export LC_ALL=C
|
|
||||||
|
|
||||||
EXIT_CODE=0
|
|
||||||
|
|
||||||
# Assume that all multiline strings passed into a runtime_error are help texts.
|
|
||||||
# This is potentially fragile, but the linter is only temporary and can safely
|
|
||||||
# be removed early 2019.
|
|
||||||
|
|
||||||
non_autogenerated_help=$(grep --perl-regexp --null-data --only-matching 'runtime_error\(\n\s*".*\\n"\n' $(git ls-files -- "*.cpp"))
|
|
||||||
if [[ ${non_autogenerated_help} != "" ]]; then
|
|
||||||
echo "Must use RPCHelpMan to generate the help for the following RPC methods:"
|
|
||||||
echo "${non_autogenerated_help}"
|
|
||||||
echo
|
|
||||||
EXIT_CODE=1
|
|
||||||
fi
|
|
||||||
exit ${EXIT_CODE}
|
|
Reference in New Issue
Block a user