diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-06-26 12:16:22 -0400 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-06-30 14:11:11 -0400 |
commit | faaeb2b0b347b40ce456a951eec5e820587e5b02 (patch) | |
tree | 47ca1c984e43fbf5333377ec51154e9dbacc0e2c /src/rpc/server.h | |
parent | fa8ec00061567e56333bb69c5623919d45a9a92d (diff) | |
download | bitcoin-faaeb2b0b347b40ce456a951eec5e820587e5b02.tar.xz |
rpc: Add CRPCCommand constructor which takes RPCHelpMan
This allows the constructor to ask the rpc manager for the name of the
rpc method or the rpc argument names instead of having it manually
passed in.
Diffstat (limited to 'src/rpc/server.h')
-rw-r--r-- | src/rpc/server.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/rpc/server.h b/src/rpc/server.h index d7a04ff6e8..1c587ae88f 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -8,6 +8,7 @@ #include <amount.h> #include <rpc/request.h> +#include <rpc/util.h> #include <functional> #include <map> @@ -85,6 +86,7 @@ void RPCUnsetTimerInterface(RPCTimerInterface *iface); void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds); typedef UniValue(*rpcfn_type)(const JSONRPCRequest& jsonRequest); +typedef RPCHelpMan (*RpcMethodFnType)(); class CRPCCommand { @@ -101,6 +103,17 @@ public: { } + //! Simplified constructor taking plain RpcMethodFnType function pointer. + CRPCCommand(std::string category, std::string name_in, RpcMethodFnType fn, std::vector<std::string> args_in) + : CRPCCommand( + category, + fn().m_name, + [fn](const JSONRPCRequest& request, UniValue& result, bool) { result = fn().HandleRequest(request); return true; }, + fn().GetArgNames(), + intptr_t(fn)) + { + } + //! 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, @@ -117,7 +130,7 @@ public: }; /** - * Bitcoin RPC command dispatcher. + * RPC command dispatcher. */ class CRPCTable { |