diff --git a/src/rpc/request.h b/src/rpc/request.h index 1751c24cd3f..27d06f3c928 100644 --- a/src/rpc/request.h +++ b/src/rpc/request.h @@ -34,7 +34,7 @@ public: UniValue id; std::string strMethod; UniValue params; - enum Mode { EXECUTE, GET_HELP } mode = EXECUTE; + enum Mode { EXECUTE, GET_HELP, GET_ARGS } mode = EXECUTE; std::string URI; std::string authUser; std::string peerAddr; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 66134a77b2f..39938f4eb98 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -149,7 +149,7 @@ static RPCHelpMan help() } if (strCommand == "dump_all_command_conversions") { // Used for testing only, undocumented - return tableRPC.dumpArgMap(); + return tableRPC.dumpArgMap(jsonRequest); } return tableRPC.help(strCommand, jsonRequest); @@ -492,13 +492,18 @@ std::vector CRPCTable::listCommands() const return commandList; } -UniValue CRPCTable::dumpArgMap() const +UniValue CRPCTable::dumpArgMap(const JSONRPCRequest& args_request) const { + JSONRPCRequest request(args_request); + request.mode = JSONRPCRequest::GET_ARGS; + 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); + UniValue result; + if (ExecuteCommands(cmd.second, request, result)) { + for (const auto& values : result.getValues()) { + ret.push_back(values); + } } } return ret; diff --git a/src/rpc/server.h b/src/rpc/server.h index fe5a791e1e3..03967020c2e 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -148,7 +148,7 @@ public: /** * Return all named arguments that need to be converted by the client from string to another JSON type */ - UniValue dumpArgMap() const; + UniValue dumpArgMap(const JSONRPCRequest& request) const; /** * Appends a CRPCCommand to the dispatch table. diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index dc57d2be072..c7472fc5c10 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -478,6 +478,9 @@ std::string RPCExamples::ToDescriptionString() const UniValue RPCHelpMan::HandleRequest(const JSONRPCRequest& request) { + if (request.mode == JSONRPCRequest::GET_ARGS) { + return GetArgMap(); + } /* * Check if the given request is valid according to this command or if * the user is asking for help information, and throw help when appropriate. @@ -561,8 +564,9 @@ std::string RPCHelpMan::ToString() const return ret; } -void RPCHelpMan::AppendArgMap(UniValue& arr) const +UniValue RPCHelpMan::GetArgMap() const { + UniValue arr{UniValue::VARR}; for (int i{0}; i < int(m_args.size()); ++i) { const auto& arg = m_args.at(i); std::vector arg_names; @@ -577,6 +581,7 @@ void RPCHelpMan::AppendArgMap(UniValue& arr) const arr.push_back(map); } } + return arr; } std::string RPCArg::GetFirstName() const diff --git a/src/rpc/util.h b/src/rpc/util.h index aaca8879009..90521949a67 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -337,8 +337,8 @@ public: UniValue HandleRequest(const JSONRPCRequest& request); std::string ToString() const; - /** Append the named args that need to be converted from string to another JSON type */ - void AppendArgMap(UniValue& arr) const; + /** Return the named args that need to be converted from string to another JSON type */ + UniValue GetArgMap() const; /** If the supplied number of args is neither too small nor too high */ bool IsValidNumArgs(size_t num_args) const; std::vector GetArgNames() const;