diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2021-01-29 18:15:48 -0500 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2021-01-29 18:15:48 -0500 |
commit | 9048c58e10841d9e1d709c0a325dd14684cec325 (patch) | |
tree | aa399e99d405412a1205c6eec856d5a886b21dc7 /src/rpc/server.cpp | |
parent | 14f3d9b908ed9e78997bfaad3d8a06357a89d46e (diff) |
Remove pointer cast in CRPCTable::dumpArgMap
CRPCTable::dumpArgMap currently works by casting RPC command unique_id
integer field to a function pointer, and then calling the function. The
unique_id field wasn't supposed to be used this way (it's meant to be
used to detect RPC aliases), and this code segfaults in the rpc_help.py
test in multiprocess PR https://github.com/bitcoin/bitcoin/pull/10102
because wallet RPC functions aren't directly accessible from the node
process.
Fix this by adding a new GET_ARGS request mode to retrieve argument
information similar to the way the GET_HELP mode retrieves help
information.
Diffstat (limited to 'src/rpc/server.cpp')
-rw-r--r-- | src/rpc/server.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 66134a77b2..39938f4eb9 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<std::string> 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; |