Skip to content

Commit

Permalink
RPC: Pass on JSONRPCRequest metadata (URI/user/etc) for "help" method
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr authored and random-zebra committed May 17, 2021
1 parent cc965fe commit 687c2fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ bool ParseBool(const UniValue& o, std::string strKey)
* Note: This interface may still be subject to change.
*/

std::string CRPCTable::help(std::string strCommand) const
std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const
{
std::string strRet;
std::string category;
Expand All @@ -199,14 +199,17 @@ std::string CRPCTable::help(std::string strCommand) const
vCommands.emplace_back(entry.second->category + entry.first, entry.second);
std::sort(vCommands.begin(), vCommands.end());

JSONRPCRequest jreq(helpreq);
jreq.fHelp = true;
jreq.params = UniValue();

for (const std::pair<std::string, const CRPCCommand*>& command : vCommands) {
const CRPCCommand* pcmd = command.second;
std::string strMethod = pcmd->name;
if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
continue;
jreq.strMethod = strMethod;
try {
JSONRPCRequest jreq;
jreq.fHelp = true;
rpcfn_type pfn = pcmd->actor;
if (setDone.insert(pfn).second)
(*pfn)(jreq);
Expand Down Expand Up @@ -248,7 +251,7 @@ UniValue help(const JSONRPCRequest& jsonRequest)
if (jsonRequest.params.size() > 0)
strCommand = jsonRequest.params[0].get_str();

return tableRPC.help(strCommand);
return tableRPC.help(strCommand, jsonRequest);
}


Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class CRPCTable
public:
CRPCTable();
const CRPCCommand* operator[](const std::string& name) const;
std::string help(std::string name) const;
std::string help(const std::string& name, const JSONRPCRequest& helpreq) const;

/**
* Execute a method.
Expand Down

0 comments on commit 687c2fd

Please sign in to comment.