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/detail/Handler.h>
9#include <xrpld/rpc/detail/Tuning.h>
11#include <xrpl/basics/Log.h>
12#include <xrpl/core/Job.h>
13#include <xrpl/core/JobQueue.h>
14#include <xrpl/core/PerfLog.h>
15#include <xrpl/json/to_string.h>
16#include <xrpl/protocol/ErrorCodes.h>
17#include <xrpl/protocol/jss.h>
18#include <xrpl/resource/Fees.h>
20#include <rpcspec/Errors.hpp>
118 int const jobCount = context.app.getJobQueue().getJobCountGE(
JtClient);
121 JLOG(context.j.debug()) <<
"Too busy for command: " << jobCount;
126 if (!context.params.isMember(jss::command) && !context.params.isMember(jss::method))
128 if (context.params.isMember(jss::command) && context.params.isMember(jss::method))
130 if (context.params[jss::command].asString() != context.params[jss::method].asString())
134 std::string
const strCommand = context.params.isMember(jss::command)
135 ? context.params[jss::command].asString()
136 : context.params[jss::method].asString();
138 JLOG(context.j.trace()) <<
"COMMAND:" << strCommand;
139 JLOG(context.j.trace()) <<
"REQUEST:" << context.params;
140 auto handler =
getHandler(context.apiVersion, context.app.config().betaRpcApi, strCommand);
142 if (handler ==
nullptr)
161 static std::atomic<std::uint64_t> kRequestId{0};
162 auto& perfLog = context.app.getPerfLog();
163 std::uint64_t
const curId = ++kRequestId;
166 perfLog.rpcStart(name, curId);
168 context.app.getJobQueue().makeLoadEvent(
JtGeneric, std::string{
"cmd:"}.append(name));
171 auto ret =
method(context, result);
174 JLOG(context.j.debug()) <<
"RPC call " << name <<
" completed in "
175 << ((
end - start).count() / 1000000000.0) <<
"seconds";
176 perfLog.rpcFinish(name, curId);
179 catch (std::exception& e)
181 perfLog.rpcError(name, curId);
182 JLOG(context.j.info()) <<
"Caught throw: " << e.
what();
197 Handler const* handler =
nullptr;
198 if (
auto const error = fillHandler(context, handler))
208 JLOG(context.
j.
debug()) <<
"start command: " << handler->
name
212 auto const ret = callMethod(context, handler->
valueMethod, handler->
name, result);
214 JLOG(context.
j.
debug()) <<
"finish command: " << handler->
name
221 return callMethod(context, handler->
valueMethod, handler->
name, result);
229 if (handler ==
nullptr)
232 return handler->role;
The function a handler dispatches to.
Charge const kFeeReferenceRpc
Charge const kFeeExceptionRpc
static constexpr int kMaxJobQueueClients
The api_version numbers this server serves.
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.
::rpc::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.