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