mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-08 03:33:32 +01:00
Remove use of CRPCTable::appendCommand in wallet code
This commit does not change behavior.
This commit is contained in:
@@ -30,6 +30,7 @@ static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server starte
|
||||
static RPCTimerInterface* timerInterface = nullptr;
|
||||
/* Map of name to timer. */
|
||||
static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers;
|
||||
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
|
||||
|
||||
struct RPCCommandExecutionInfo
|
||||
{
|
||||
@@ -173,11 +174,11 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
|
||||
{
|
||||
std::string strRet;
|
||||
std::string category;
|
||||
std::set<rpcfn_type> setDone;
|
||||
std::set<intptr_t> setDone;
|
||||
std::vector<std::pair<std::string, const CRPCCommand*> > vCommands;
|
||||
|
||||
for (const auto& entry : mapCommands)
|
||||
vCommands.push_back(make_pair(entry.second->category + entry.first, entry.second));
|
||||
vCommands.push_back(make_pair(entry.second.front()->category + entry.first, entry.second.front()));
|
||||
sort(vCommands.begin(), vCommands.end());
|
||||
|
||||
JSONRPCRequest jreq(helpreq);
|
||||
@@ -193,9 +194,9 @@ std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest&
|
||||
jreq.strMethod = strMethod;
|
||||
try
|
||||
{
|
||||
rpcfn_type pfn = pcmd->actor;
|
||||
if (setDone.insert(pfn).second)
|
||||
(*pfn)(jreq);
|
||||
UniValue unused_result;
|
||||
if (setDone.insert(pcmd->unique_id).second)
|
||||
pcmd->actor(jreq, unused_result, true /* last_handler */);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
@@ -337,32 +338,32 @@ CRPCTable::CRPCTable()
|
||||
const CRPCCommand *pcmd;
|
||||
|
||||
pcmd = &vRPCCommands[vcidx];
|
||||
mapCommands[pcmd->name] = pcmd;
|
||||
mapCommands[pcmd->name].push_back(pcmd);
|
||||
}
|
||||
}
|
||||
|
||||
const CRPCCommand *CRPCTable::operator[](const std::string &name) const
|
||||
{
|
||||
std::map<std::string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
|
||||
if (it == mapCommands.end())
|
||||
return nullptr;
|
||||
return (*it).second;
|
||||
}
|
||||
|
||||
bool CRPCTable::appendCommand(const std::string& name, const CRPCCommand* pcmd)
|
||||
{
|
||||
if (IsRPCRunning())
|
||||
return false;
|
||||
|
||||
// don't allow overwriting for now
|
||||
std::map<std::string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
|
||||
if (it != mapCommands.end())
|
||||
return false;
|
||||
|
||||
mapCommands[name] = pcmd;
|
||||
mapCommands[name].push_back(pcmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CRPCTable::removeCommand(const std::string& name, const CRPCCommand* pcmd)
|
||||
{
|
||||
auto it = mapCommands.find(name);
|
||||
if (it != mapCommands.end()) {
|
||||
auto new_end = std::remove(it->second.begin(), it->second.end(), pcmd);
|
||||
if (it->second.end() != new_end) {
|
||||
it->second.erase(new_end, it->second.end());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void StartRPC()
|
||||
{
|
||||
LogPrint(BCLog::RPC, "Starting RPC\n");
|
||||
@@ -543,18 +544,28 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
|
||||
}
|
||||
|
||||
// Find method
|
||||
const CRPCCommand *pcmd = tableRPC[request.strMethod];
|
||||
if (!pcmd)
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
|
||||
auto it = mapCommands.find(request.strMethod);
|
||||
if (it != mapCommands.end()) {
|
||||
UniValue result;
|
||||
for (const auto& command : it->second) {
|
||||
if (ExecuteCommand(*command, request, result, &command == &it->second.back())) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
|
||||
}
|
||||
|
||||
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler)
|
||||
{
|
||||
try
|
||||
{
|
||||
RPCCommandExecution execution(request.strMethod);
|
||||
// Execute, convert arguments to array if necessary
|
||||
if (request.params.isObject()) {
|
||||
return pcmd->actor(transformNamedArguments(request, pcmd->argNames));
|
||||
return command.actor(transformNamedArguments(request, command.argNames), result, last_handler);
|
||||
} else {
|
||||
return pcmd->actor(request);
|
||||
return command.actor(request, result, last_handler);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
||||
Reference in New Issue
Block a user