rippled
Loading...
Searching...
No Matches
Handler.h
1#pragma once
2
3#include <xrpld/app/ledger/LedgerMaster.h>
4#include <xrpld/rpc/RPCHandler.h>
5#include <xrpld/rpc/Status.h>
6#include <xrpld/rpc/detail/Tuning.h>
7
8#include <xrpl/protocol/ApiVersion.h>
9#include <xrpl/server/NetworkOPs.h>
10
11namespace Json {
12class Object;
13} // namespace Json
14
15namespace xrpl {
16namespace RPC {
17
18// Under what condition can we call this RPC?
25
39
40Handler const*
41getHandler(unsigned int version, bool betaEnabled, std::string const&);
42
44template <class Value>
46makeObjectValue(Value const& value, Json::StaticString const& field = jss::message)
47{
49 result[field] = value;
50 return result;
51}
52
56
57template <class T>
59conditionMet(Condition condition_required, T& context)
60{
61 if (context.app.getOPs().isAmendmentBlocked() && (condition_required != NO_CONDITION))
62 {
64 }
65
66 if (context.app.getOPs().isUNLBlocked() && (condition_required != NO_CONDITION))
67 {
69 }
70
71 if ((condition_required != NO_CONDITION) &&
72 (context.netOps.getOperatingMode() < OperatingMode::SYNCING))
73 {
74 JLOG(context.j.info()) << "Insufficient network mode for RPC: "
75 << context.netOps.strOperatingMode();
76
77 if (context.apiVersion == 1)
78 return rpcNO_NETWORK;
79 return rpcNOT_SYNCED;
80 }
81
82 if (!context.app.config().standalone() && condition_required != NO_CONDITION)
83 {
84 if (context.ledgerMaster.getValidatedLedgerAge() > Tuning::maxValidatedLedgerAge)
85 {
86 if (context.apiVersion == 1)
87 return rpcNO_CURRENT;
88 return rpcNOT_SYNCED;
89 }
90
91 auto const cID = context.ledgerMaster.getCurrentLedgerIndex();
92 auto const vID = context.ledgerMaster.getValidLedgerIndex();
93
94 if (cID + 10 < vID)
95 {
96 JLOG(context.j.debug()) << "Current ledger ID(" << cID
97 << ") is less than validated ledger ID(" << vID << ")";
98 if (context.apiVersion == 1)
99 return rpcNO_CURRENT;
100 return rpcNOT_SYNCED;
101 }
102 }
103
104 if ((condition_required != NO_CONDITION) && !context.ledgerMaster.getClosedLedger())
105 {
106 if (context.apiVersion == 1)
107 return rpcNO_CLOSED;
108 return rpcNOT_SYNCED;
109 }
110
111 return rpcSUCCESS;
112}
113
114} // namespace RPC
115} // namespace xrpl
Lightweight wrapper to tag static string.
Definition json_value.h:44
Represents a JSON value.
Definition json_value.h:130
JSON (JavaScript Object Notation).
Definition json_errors.h:5
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:26
Json::Value makeObjectValue(Value const &value, Json::StaticString const &field=jss::message)
Return a Json::objectValue with a single entry.
Definition Handler.h:46
@ NEEDS_NETWORK_CONNECTION
Definition Handler.h:21
@ NO_CONDITION
Definition Handler.h:20
@ NEEDS_CLOSED_LEDGER
Definition Handler.h:23
@ NEEDS_CURRENT_LEDGER
Definition Handler.h:22
std::set< char const * > getHandlerNames()
Return names of all methods.
Definition Handler.cpp:260
Handler const * getHandler(unsigned version, bool betaEnabled, std::string const &name)
Definition Handler.cpp:254
static constexpr auto apiMinimumSupportedVersion
Definition ApiVersion.h:41
static constexpr auto apiMaximumValidVersion
Definition ApiVersion.h:46
error_code_i conditionMet(Condition condition_required, T &context)
Definition Handler.h:59
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Role
Indicates the level of administrative permission to grant.
Definition Role.h:24
@ SYNCING
fallen slightly behind
error_code_i
Definition ErrorCodes.h:20
@ rpcNO_NETWORK
Definition ErrorCodes.h:46
@ rpcNO_CLOSED
Definition ErrorCodes.h:44
@ rpcNO_CURRENT
Definition ErrorCodes.h:45
@ rpcAMENDMENT_BLOCKED
Definition ErrorCodes.h:41
@ rpcEXPIRED_VALIDATOR_LIST
Definition ErrorCodes.h:117
@ rpcNOT_SYNCED
Definition ErrorCodes.h:47
@ rpcSUCCESS
Definition ErrorCodes.h:24
unsigned maxApiVer_
Definition Handler.h:37
char const * name_
Definition Handler.h:31
Method< Json::Value > valueMethod_
Definition Handler.h:32
unsigned minApiVer_
Definition Handler.h:36
RPC::Condition condition_
Definition Handler.h:34
Status represents the results of an operation that might fail.
Definition Status.h:20