Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/server.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Copyright (c) 2018 The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "base58.h" | #include "base58.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "fs.h" | #include "fs.h" | ||||
Show All 30 Lines | UniValue RPCServer::ExecuteCommand(Config &config, | ||||
// Return immediately if in warmup | // Return immediately if in warmup | ||||
{ | { | ||||
LOCK(cs_rpcWarmup); | LOCK(cs_rpcWarmup); | ||||
if (fRPCInWarmup) { | if (fRPCInWarmup) { | ||||
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus); | throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus); | ||||
} | } | ||||
} | } | ||||
// TODO Only call tableRPC.execute() if no context-sensitive RPC command | std::string commandName = request.strMethod; | ||||
// exists | RPCCommand *command = MatchCommand(commandName)(request); | ||||
if (command != nullptr) { | |||||
return command->Execute(request.params); | |||||
} | |||||
// TODO Remove the below call to tableRPC.execute() and only call it for | |||||
// context-free RPC commands via an implementation of RPCCommand. | |||||
// Check if context-free RPC method is valid and execute it | // Check if context-free RPC method is valid and execute it | ||||
return tableRPC.execute(config, request); | return tableRPC.execute(config, request); | ||||
} | } | ||||
namespace { | |||||
static RPCCommand *GetCommandErrorFactory(const JSONRPCRequest &) { | |||||
return nullptr; | |||||
} | |||||
} | |||||
std::function<RPCCommand *(const JSONRPCRequest &)> | |||||
RPCServer::MatchCommand(std::string name) const { | |||||
auto iter = commands.find(name); | |||||
if (iter == commands.end()) { | |||||
return &::GetCommandErrorFactory; | |||||
} | |||||
return iter->second; | |||||
} | |||||
static struct CRPCSignals { | static struct CRPCSignals { | ||||
boost::signals2::signal<void()> Started; | boost::signals2::signal<void()> Started; | ||||
boost::signals2::signal<void()> Stopped; | boost::signals2::signal<void()> Stopped; | ||||
boost::signals2::signal<void(const ContextFreeRPCCommand &)> PreCommand; | boost::signals2::signal<void(const ContextFreeRPCCommand &)> PreCommand; | ||||
} g_rpcSignals; | } g_rpcSignals; | ||||
void RPCServerSignals::OnStarted(std::function<void()> slot) { | void RPCServerSignals::OnStarted(std::function<void()> slot) { | ||||
g_rpcSignals.Started.connect(slot); | g_rpcSignals.Started.connect(slot); | ||||
▲ Show 20 Lines • Show All 527 Lines • Show Last 20 Lines |