1#include <xrpld/app/ledger/InboundLedgers.h>
2#include <xrpld/app/ledger/LedgerMaster.h>
3#include <xrpld/app/ledger/LedgerToJson.h>
4#include <xrpld/app/main/Application.h>
5#include <xrpld/core/Config.h>
6#include <xrpld/rpc/Context.h>
7#include <xrpld/rpc/RPCHandler.h>
8#include <xrpld/rpc/Role.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/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>
19#include <xrpl/server/InfoSub.h>
20#include <xrpl/server/NetworkOPs.h>
111fillHandler(JsonContext& context, Handler
const*& result)
116 int const jobCount = context.app.getJobQueue().getJobCountGE(
jtCLIENT);
119 JLOG(context.j.debug()) <<
"Too busy for command: " << jobCount;
124 if (!context.params.isMember(jss::command) && !context.params.isMember(jss::method))
126 if (context.params.isMember(jss::command) && context.params.isMember(jss::method))
128 if (context.params[jss::command].asString() != context.params[jss::method].asString())
132 std::string const strCommand = context.params.isMember(jss::command)
133 ? context.params[jss::command].asString()
134 : context.params[jss::method].asString();
136 JLOG(context.j.trace()) <<
"COMMAND:" << strCommand;
137 JLOG(context.j.trace()) <<
"REQUEST:" << context.params;
138 auto handler =
getHandler(context.apiVersion, context.app.config().BETA_RPC_API, strCommand);
140 if (handler ==
nullptr)
156template <
class Object,
class Method>
158callMethod(JsonContext& context, Method method,
std::string const& name, Object& result)
161 auto& perfLog = context.app.getPerfLog();
165 perfLog.rpcStart(name, curId);
166 auto v = context.app.getJobQueue().makeLoadEvent(
jtGENERIC,
"cmd:" + name);
169 auto ret = method(context, result);
172 JLOG(context.j.debug()) <<
"RPC call " << name <<
" completed in "
173 << ((
end - start).
count() / 1000000000.0) <<
"seconds";
174 perfLog.rpcFinish(name, curId);
179 perfLog.rpcError(name, curId);
180 JLOG(context.j.info()) <<
"Caught throw: " << e.
what();
195 Handler const* handler =
nullptr;
196 if (
auto error = fillHandler(context, handler))
207 <<
"start command: " << handler->
name_ <<
", user: " << context.
headers.
user
210 auto ret = callMethod(context, method, handler->
name_, result);
213 <<
"finish command: " << handler->
name_ <<
", user: " << context.
headers.
user
219 auto ret = callMethod(context, method, handler->
name_, result);
231 if (handler ==
nullptr)
234 return handler->role_;
Status
Return codes from Backend operations.
static int constexpr maxJobQueueClients
Role roleRequired(unsigned int version, bool betaEnabled, std::string const &method)
Handler const * getHandler(unsigned version, bool betaEnabled, std::string const &name)
Status doCommand(RPC::JsonContext &context, Json::Value &result)
Execute an RPC command and store the results in a Json::Value.
error_code_i conditionMet(Condition condition_required, T &context)
void inject_error(error_code_i code, Json::Value &json)
Add or update the json update to reflect the error code.
Charge const feeReferenceRPC
Charge const feeExceptionRPC
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Role
Indicates the level of administrative permission to grant.
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Method< Json::Value > valueMethod_