diff --git a/src/qt/test/rpcnestedtests.cpp b/src/qt/test/rpcnestedtests.cpp --- a/src/qt/test/rpcnestedtests.cpp +++ b/src/qt/test/rpcnestedtests.cpp @@ -29,7 +29,7 @@ return request.params.write(0, 0); } -static const ContextFreeRPCCommand vRPCCommands[] = { +static const CRPCCommand vRPCCommands[] = { {"test", "rpcNestedTest", &rpcNestedTest_rpc, {}}, }; diff --git a/src/rpc/abc.cpp b/src/rpc/abc.cpp --- a/src/rpc/abc.cpp +++ b/src/rpc/abc.cpp @@ -81,7 +81,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "network", "getexcessiveblock", getexcessiveblock, {}}, diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -75,7 +75,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "avalanche", "getavalanchekey", getavalanchekey, {}}, diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2771,7 +2771,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "blockchain", "getbestblockhash", getbestblockhash, {} }, diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -865,7 +865,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ---------- ------------------------ ---------------------- ---------- {"mining", "getnetworkhashps", getnetworkhashps, {"nblocks", "height"}}, diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -565,7 +565,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "control", "getmemoryinfo", getmemoryinfo, {"mode"} }, diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -903,7 +903,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "network", "getconnectioncount", getconnectioncount, {} }, diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -2018,7 +2018,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "rawtransactions", "getrawtransaction", getrawtransaction, {"txid","verbose","blockhash"} }, diff --git a/src/rpc/register.h b/src/rpc/register.h --- a/src/rpc/register.h +++ b/src/rpc/register.h @@ -5,8 +5,10 @@ #ifndef BITCOIN_RPC_REGISTER_H #define BITCOIN_RPC_REGISTER_H -/** These are in one header file to avoid creating tons of single-function - * headers for everything under src/rpc/ */ +/** + * These are in one header file to avoid creating tons of single-function + * headers for everything under src/rpc/ + */ class CRPCTable; class RPCServer; @@ -25,11 +27,7 @@ /** Register Avalanche RPC commands */ void RegisterAvalancheRPCCommands(CRPCTable &tableRPC); -/** - * Register all context-free (legacy) RPC commands, except for wallet and dump - * RPC commands. - */ -static inline void RegisterAllContextFreeRPCCommands(CRPCTable &t) { +static inline void RegisterAllCoreRPCCommands(CRPCTable &t) { RegisterBlockchainRPCCommands(t); RegisterNetRPCCommands(t); RegisterMiscRPCCommands(t); @@ -47,7 +45,7 @@ CRPCTable &rpcTable) { // TODO Register context-sensitive RPC commands using rpcServer - RegisterAllContextFreeRPCCommands(rpcTable); + RegisterAllCoreRPCCommands(rpcTable); } #endif // BITCOIN_RPC_REGISTER_H diff --git a/src/rpc/server.h b/src/rpc/server.h --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -26,7 +26,7 @@ static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION = 1; -class ContextFreeRPCCommand; +class CRPCCommand; namespace RPCServerSignals { void OnStarted(std::function slot); @@ -177,7 +177,7 @@ typedef UniValue (*const_rpcfn_type)(const Config &config, const JSONRPCRequest &jsonRequest); -class ContextFreeRPCCommand { +class CRPCCommand { public: std::string category; std::string name; @@ -192,8 +192,8 @@ public: std::vector argNames; - ContextFreeRPCCommand(std::string _category, std::string _name, - rpcfn_type _actor, std::vector _argNames) + CRPCCommand(std::string _category, std::string _name, rpcfn_type _actor, + std::vector _argNames) : category{std::move(_category)}, name{std::move(_name)}, useConstConfig{false}, argNames{std::move(_argNames)} { actor.fn = _actor; @@ -204,9 +204,8 @@ * can call the command through the proper pointer. Casting constness * on parameters of function is undefined behavior. */ - ContextFreeRPCCommand(std::string _category, std::string _name, - const_rpcfn_type _actor, - std::vector _argNames) + CRPCCommand(std::string _category, std::string _name, + const_rpcfn_type _actor, std::vector _argNames) : category{std::move(_category)}, name{std::move(_name)}, useConstConfig{true}, argNames{std::move(_argNames)} { actor.cfn = _actor; @@ -223,11 +222,11 @@ */ class CRPCTable { private: - std::map mapCommands; + std::map mapCommands; public: CRPCTable(); - const ContextFreeRPCCommand *operator[](const std::string &name) const; + const CRPCCommand *operator[](const std::string &name) const; std::string help(Config &config, const std::string &name, const JSONRPCRequest &helpreq) const; @@ -246,7 +245,7 @@ std::vector listCommands() const; /** - * Appends a ContextFreeRPCCommand to the dispatch table. + * Appends a CRPCCommand to the dispatch table. * * Returns false if RPC server is already running (dump concurrency * protection). @@ -260,8 +259,7 @@ * between calls based on method name, and aliased commands can also * register different names, types, and numbers of parameters. */ - bool appendCommand(const std::string &name, - const ContextFreeRPCCommand *pcmd); + bool appendCommand(const std::string &name, const CRPCCommand *pcmd); }; bool IsDeprecatedRPCEnabled(ArgsManager &args, const std::string &method); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -226,9 +226,8 @@ const JSONRPCRequest &helpreq) const { std::string strRet; std::string category; - std::set setDone; - std::vector> - vCommands; + std::set setDone; + std::vector> vCommands; for (const auto &entry : mapCommands) { vCommands.push_back( @@ -240,9 +239,9 @@ jreq.fHelp = true; jreq.params = UniValue(); - for (const std::pair &command : + for (const std::pair &command : vCommands) { - const ContextFreeRPCCommand *pcmd = command.second; + const CRPCCommand *pcmd = command.second; std::string strMethod = pcmd->name; if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand) { @@ -377,7 +376,7 @@ } // clang-format off -static const ContextFreeRPCCommand vRPCCommands[] = { +static const CRPCCommand vRPCCommands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- /* Overall control/query calls */ @@ -392,16 +391,15 @@ unsigned int vcidx; for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++) { - const ContextFreeRPCCommand *pcmd; + const CRPCCommand *pcmd; pcmd = &vRPCCommands[vcidx]; mapCommands[pcmd->name] = pcmd; } } -const ContextFreeRPCCommand *CRPCTable:: -operator[](const std::string &name) const { - std::map::const_iterator it = +const CRPCCommand *CRPCTable::operator[](const std::string &name) const { + std::map::const_iterator it = mapCommands.find(name); if (it == mapCommands.end()) { return nullptr; @@ -411,13 +409,13 @@ } bool CRPCTable::appendCommand(const std::string &name, - const ContextFreeRPCCommand *pcmd) { + const CRPCCommand *pcmd) { if (IsRPCRunning()) { return false; } // don't allow overwriting for now - std::map::const_iterator it = + std::map::const_iterator it = mapCommands.find(name); if (it != mapCommands.end()) { return false; @@ -571,7 +569,7 @@ // Check if legacy RPC method is valid. // See RPCServer::ExecuteCommand for context-sensitive RPC commands. - const ContextFreeRPCCommand *pcmd = tableRPC[request.strMethod]; + const CRPCCommand *pcmd = tableRPC[request.strMethod]; if (!pcmd) { throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found"); } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1713,7 +1713,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "wallet", "abortrescan", abortrescan, {} }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4852,7 +4852,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "generating", "generate", generate, {"nblocks","maxtries"} }, diff --git a/src/zmq/zmqrpc.cpp b/src/zmq/zmqrpc.cpp --- a/src/zmq/zmqrpc.cpp +++ b/src/zmq/zmqrpc.cpp @@ -51,7 +51,7 @@ } // clang-format off -static const ContextFreeRPCCommand commands[] = { +static const CRPCCommand commands[] = { // category name actor (function) argNames // ----------------- ------------------------ ----------------------- ---------- { "zmq", "getzmqnotifications", getzmqnotifications, {} }, diff --git a/test/lint/check-rpc-mappings.py b/test/lint/check-rpc-mappings.py --- a/test/lint/check-rpc-mappings.py +++ b/test/lint/check-rpc-mappings.py @@ -51,7 +51,7 @@ line = line.rstrip() if not in_rpcs: if re.match( - r"static const ContextFreeRPCCommand .*\[\] =", line): + r"static const CRPCCommand .*\[\] =", line): in_rpcs = True else: if line.startswith('};'):