rippled
Loading...
Searching...
No Matches
Handler.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_RPC_HANDLER_H_INCLUDED
21#define RIPPLE_RPC_HANDLER_H_INCLUDED
22
23#include <xrpld/app/ledger/LedgerMaster.h>
24#include <xrpld/app/misc/NetworkOPs.h>
25#include <xrpld/rpc/RPCHandler.h>
26#include <xrpld/rpc/Status.h>
27#include <xrpld/rpc/detail/Tuning.h>
28
29#include <xrpl/protocol/ApiVersion.h>
30
31namespace Json {
32class Object;
33}
34
35namespace ripple {
36namespace RPC {
37
38// Under what condition can we call this RPC?
45
59
60Handler const*
61getHandler(unsigned int version, bool betaEnabled, std::string const&);
62
64template <class Value>
67 Value const& value,
68 Json::StaticString const& field = jss::message)
69{
71 result[field] = value;
72 return result;
73}
74
78
79template <class T>
81conditionMet(Condition condition_required, T& context)
82{
83 if (context.app.getOPs().isAmendmentBlocked() &&
84 (condition_required != NO_CONDITION))
85 {
87 }
88
89 if (context.app.getOPs().isUNLBlocked() &&
90 (condition_required != NO_CONDITION))
91 {
93 }
94
95 if ((condition_required != NO_CONDITION) &&
96 (context.netOps.getOperatingMode() < OperatingMode::SYNCING))
97 {
98 JLOG(context.j.info()) << "Insufficient network mode for RPC: "
99 << context.netOps.strOperatingMode();
100
101 if (context.apiVersion == 1)
102 return rpcNO_NETWORK;
103 return rpcNOT_SYNCED;
104 }
105
106 if (!context.app.config().standalone() &&
107 condition_required != NO_CONDITION)
108 {
109 if (context.ledgerMaster.getValidatedLedgerAge() >
111 {
112 if (context.apiVersion == 1)
113 return rpcNO_CURRENT;
114 return rpcNOT_SYNCED;
115 }
116
117 auto const cID = context.ledgerMaster.getCurrentLedgerIndex();
118 auto const vID = context.ledgerMaster.getValidLedgerIndex();
119
120 if (cID + 10 < vID)
121 {
122 JLOG(context.j.debug())
123 << "Current ledger ID(" << cID
124 << ") is less than validated ledger ID(" << vID << ")";
125 if (context.apiVersion == 1)
126 return rpcNO_CURRENT;
127 return rpcNOT_SYNCED;
128 }
129 }
130
131 if ((condition_required != NO_CONDITION) &&
132 !context.ledgerMaster.getClosedLedger())
133 {
134 if (context.apiVersion == 1)
135 return rpcNO_CLOSED;
136 return rpcNOT_SYNCED;
137 }
138
139 return rpcSUCCESS;
140}
141
142} // namespace RPC
143} // namespace ripple
144
145#endif
Lightweight wrapper to tag static string.
Definition json_value.h:63
Represents a JSON value.
Definition json_value.h:149
JSON (JavaScript Object Notation).
Definition json_errors.h:25
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
@ NEEDS_CURRENT_LEDGER
Definition Handler.h:42
@ NEEDS_NETWORK_CONNECTION
Definition Handler.h:41
@ NO_CONDITION
Definition Handler.h:40
@ NEEDS_CLOSED_LEDGER
Definition Handler.h:43
std::set< char const * > getHandlerNames()
Return names of all methods.
Definition Handler.cpp:319
Json::Value makeObjectValue(Value const &value, Json::StaticString const &field=jss::message)
Return a Json::objectValue with a single entry.
Definition Handler.h:66
static constexpr auto apiMaximumValidVersion
Definition ApiVersion.h:67
Handler const * getHandler(unsigned version, bool betaEnabled, std::string const &name)
Definition Handler.cpp:313
error_code_i conditionMet(Condition condition_required, T &context)
Definition Handler.h:81
static constexpr auto apiMinimumSupportedVersion
Definition ApiVersion.h:61
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ rpcNO_NETWORK
Definition ErrorCodes.h:66
@ rpcAMENDMENT_BLOCKED
Definition ErrorCodes.h:61
@ rpcSUCCESS
Definition ErrorCodes.h:44
@ rpcNO_CURRENT
Definition ErrorCodes.h:65
@ rpcEXPIRED_VALIDATOR_LIST
Definition ErrorCodes.h:137
@ rpcNO_CLOSED
Definition ErrorCodes.h:64
@ rpcNOT_SYNCED
Definition ErrorCodes.h:67
@ SYNCING
fallen slightly behind
Role
Indicates the level of administrative permission to grant.
Definition Role.h:44
RPC::Condition condition_
Definition Handler.h:54
char const * name_
Definition Handler.h:51
Method< Json::Value > valueMethod_
Definition Handler.h:52
unsigned maxApiVer_
Definition Handler.h:57
unsigned minApiVer_
Definition Handler.h:56
Status represents the results of an operation that might fail.
Definition Status.h:40