1#include <xrpld/rpc/RPCHandler.h>
3#include <xrpld/app/ledger/LedgerMaster.h>
4#include <xrpld/app/main/Application.h>
5#include <xrpld/core/Config.h>
6#include <xrpld/rpc/Context.h>
7#include <xrpld/rpc/Role.h>
8#include <xrpld/rpc/Status.h>
9#include <xrpld/rpc/detail/Handler.h>
10#include <xrpld/rpc/detail/Tuning.h>
12#include <xrpl/basics/Log.h>
13#include <xrpl/core/Job.h>
14#include <xrpl/core/JobQueue.h>
15#include <xrpl/core/PerfLog.h>
16#include <xrpl/json/to_string.h>
17#include <xrpl/protocol/ErrorCodes.h>
18#include <xrpl/protocol/jss.h>
19#include <xrpl/resource/Fees.h>
117 int const jobCount = context.app.getJobQueue().getJobCountGE(
JtClient);
120 JLOG(context.j.debug()) <<
"Too busy for command: " << jobCount;
125 if (!context.params.isMember(jss::command) && !context.params.isMember(jss::method))
127 if (context.params.isMember(jss::command) && context.params.isMember(jss::method))
129 if (context.params[jss::command].asString() != context.params[jss::method].asString())
133 std::string
const strCommand = context.params.isMember(jss::command)
134 ? context.params[jss::command].asString()
135 : context.params[jss::method].asString();
137 JLOG(context.j.trace()) <<
"COMMAND:" << strCommand;
138 JLOG(context.j.trace()) <<
"REQUEST:" << context.params;
139 auto handler =
getHandler(context.apiVersion, context.app.config().betaRpcApi, strCommand);
141 if (handler ==
nullptr)
160 static std::atomic<std::uint64_t> kRequestId{0};
161 auto& perfLog = context.app.getPerfLog();
162 std::uint64_t
const curId = ++kRequestId;
165 perfLog.rpcStart(name, curId);
167 context.app.getJobQueue().makeLoadEvent(
JtGeneric, std::string{
"cmd:"}.append(name));
170 auto ret =
method(context, result);
173 JLOG(context.j.debug()) <<
"RPC call " << name <<
" completed in "
174 << ((
end - start).count() / 1000000000.0) <<
"seconds";
175 perfLog.rpcFinish(name, curId);
178 catch (std::exception& e)
180 perfLog.rpcError(name, curId);
181 JLOG(context.j.info()) <<
"Caught throw: " << e.
what();
196 Handler const* handler =
nullptr;
197 if (
auto error = fillHandler(context, handler))
207 JLOG(context.
j.
debug()) <<
"start command: " << handler->
name
211 auto const ret = callMethod(context, handler->
valueMethod, handler->
name, result);
213 JLOG(context.
j.
debug()) <<
"finish command: " << handler->
name
220 return callMethod(context, handler->
valueMethod, handler->
name, result);
228 if (handler ==
nullptr)
231 return handler->role;
The function a handler dispatches to.
Charge const kFeeReferenceRpc
Charge const kFeeExceptionRpc
static constexpr int kMaxJobQueueClients
API version numbers used in later API versions.
ErrorCodeI conditionMet(Condition conditionRequired, T &context)
Role roleRequired(unsigned int version, bool betaEnabled, std::string_view method)
Handler const * getHandler(unsigned version, bool betaEnabled, std::string_view name)
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
Status doCommand(rpc::JsonContext &context, json::Value &result)
Execute an RPC command and store the results in a json::Value.
Role
Indicates the level of administrative permission to grant.
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Status represents the results of an operation that might fail.