diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-01-12 06:28:13 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-01-28 08:16:34 +0100 |
commit | fa92912b4bb4629addcbfdfb7cc000be701614af (patch) | |
tree | 2e8b64d487f766ec44d057f8f5e8aee6b2354217 /src/rpc | |
parent | faf835680be39811827504f77005b6603165f53e (diff) | |
download | bitcoin-fa92912b4bb4629addcbfdfb7cc000be701614af.tar.xz |
rpc: Use RPCHelpMan for check-rpc-mappings linter
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/server.cpp | 19 | ||||
-rw-r--r-- | src/rpc/server.h | 4 | ||||
-rw-r--r-- | src/rpc/util.cpp | 18 | ||||
-rw-r--r-- | src/rpc/util.h | 2 |
4 files changed, 42 insertions, 1 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index f32d9abac6..e8abc020da 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -144,8 +144,13 @@ static RPCHelpMan help() [&](const RPCHelpMan& self, const JSONRPCRequest& jsonRequest) -> UniValue { std::string strCommand; - if (jsonRequest.params.size() > 0) + if (jsonRequest.params.size() > 0) { strCommand = jsonRequest.params[0].get_str(); + } + if (strCommand == "dump_all_command_conversions") { + // Used for testing only, undocumented + return tableRPC.dumpArgMap(); + } return tableRPC.help(strCommand, jsonRequest); }, @@ -479,6 +484,18 @@ std::vector<std::string> CRPCTable::listCommands() const return commandList; } +UniValue CRPCTable::dumpArgMap() const +{ + UniValue ret{UniValue::VARR}; + for (const auto& cmd : mapCommands) { + for (const auto& c : cmd.second) { + const auto help = RpcMethodFnType(c->unique_id)(); + help.AppendArgMap(ret); + } + } + return ret; +} + void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface) { if (!timerInterface) diff --git a/src/rpc/server.h b/src/rpc/server.h index 040192b455..d2f44334ae 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -147,6 +147,10 @@ public: */ std::vector<std::string> listCommands() const; + /** + * Return all named arguments that need to be converted by the client from string to another JSON type + */ + UniValue dumpArgMap() const; /** * Appends a CRPCCommand to the dispatch table. diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 31072114da..bfdba5253c 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -549,6 +549,24 @@ std::string RPCHelpMan::ToString() const return ret; } +void RPCHelpMan::AppendArgMap(UniValue& arr) const +{ + for (int i{0}; i < int(m_args.size()); ++i) { + const auto& arg = m_args.at(i); + std::vector<std::string> arg_names; + boost::split(arg_names, arg.m_names, boost::is_any_of("|")); + for (const auto& arg_name : arg_names) { + UniValue map{UniValue::VARR}; + map.push_back(m_name); + map.push_back(i); + map.push_back(arg_name); + map.push_back(arg.m_type == RPCArg::Type::STR || + arg.m_type == RPCArg::Type::STR_HEX); + arr.push_back(map); + } + } +} + std::string RPCArg::GetFirstName() const { return m_names.substr(0, m_names.find("|")); diff --git a/src/rpc/util.h b/src/rpc/util.h index 942c243718..444a013ca1 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -336,6 +336,8 @@ public: RPCHelpMan(std::string name, std::string description, std::vector<RPCArg> args, RPCResults results, RPCExamples examples, RPCMethodImpl fun); std::string ToString() const; + /** Append the named args that need to be converted from string to another JSON type */ + void AppendArgMap(UniValue& arr) const; UniValue HandleRequest(const JSONRPCRequest& request) { Check(request); |