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}
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) && (context.netOps.getOperatingMode() < OperatingMode::SYNCING))
72 {
73 JLOG(context.j.info()) << "Insufficient network mode for RPC: " << context.netOps.strOperatingMode();
74
75 if (context.apiVersion == 1)
76 return rpcNO_NETWORK;
77 return rpcNOT_SYNCED;
78 }
79
80 if (!context.app.config().standalone() && condition_required != NO_CONDITION)
81 {
82 if (context.ledgerMaster.getValidatedLedgerAge() > Tuning::maxValidatedLedgerAge)
83 {
84 if (context.apiVersion == 1)
85 return rpcNO_CURRENT;
86 return rpcNOT_SYNCED;
87 }
88
89 auto const cID = context.ledgerMaster.getCurrentLedgerIndex();
90 auto const vID = context.ledgerMaster.getValidLedgerIndex();
91
92 if (cID + 10 < vID)
93 {
94 JLOG(context.j.debug()) << "Current ledger ID(" << cID << ") is less than validated ledger ID(" << vID
95 << ")";
96 if (context.apiVersion == 1)
97 return rpcNO_CURRENT;
98 return rpcNOT_SYNCED;
99 }
100 }
101
102 if ((condition_required != NO_CONDITION) && !context.ledgerMaster.getClosedLedger())
103 {
104 if (context.apiVersion == 1)
105 return rpcNO_CLOSED;
106 return rpcNOT_SYNCED;
107 }
108
109 return rpcSUCCESS;
110}
111
112} // namespace RPC
113} // 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:242
Handler const * getHandler(unsigned version, bool betaEnabled, std::string const &name)
Definition Handler.cpp:236
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