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/RPCHelpers.h>
28#include <xrpld/rpc/detail/Tuning.h>
29
30namespace Json {
31class Object;
32}
33
34namespace ripple {
35namespace RPC {
36
37// Under what condition can we call this RPC?
44
58
59Handler const*
60getHandler(unsigned int version, bool betaEnabled, std::string const&);
61
63template <class Value>
66 Value const& value,
67 Json::StaticString const& field = jss::message)
68{
70 result[field] = value;
71 return result;
72}
73
77
78template <class T>
80conditionMet(Condition condition_required, T& context)
81{
82 if (context.app.getOPs().isAmendmentBlocked() &&
83 (condition_required != NO_CONDITION))
84 {
86 }
87
88 if (context.app.getOPs().isUNLBlocked() &&
89 (condition_required != NO_CONDITION))
90 {
92 }
93
94 if ((condition_required != NO_CONDITION) &&
95 (context.netOps.getOperatingMode() < OperatingMode::SYNCING))
96 {
97 JLOG(context.j.info()) << "Insufficient network mode for RPC: "
98 << context.netOps.strOperatingMode();
99
100 if (context.apiVersion == 1)
101 return rpcNO_NETWORK;
102 return rpcNOT_SYNCED;
103 }
104
105 if (!context.app.config().standalone() &&
106 condition_required != NO_CONDITION)
107 {
108 if (context.ledgerMaster.getValidatedLedgerAge() >
110 {
111 if (context.apiVersion == 1)
112 return rpcNO_CURRENT;
113 return rpcNOT_SYNCED;
114 }
115
116 auto const cID = context.ledgerMaster.getCurrentLedgerIndex();
117 auto const vID = context.ledgerMaster.getValidLedgerIndex();
118
119 if (cID + 10 < vID)
120 {
121 JLOG(context.j.debug())
122 << "Current ledger ID(" << cID
123 << ") is less than validated ledger ID(" << vID << ")";
124 if (context.apiVersion == 1)
125 return rpcNO_CURRENT;
126 return rpcNOT_SYNCED;
127 }
128 }
129
130 if ((condition_required != NO_CONDITION) &&
131 !context.ledgerMaster.getClosedLedger())
132 {
133 if (context.apiVersion == 1)
134 return rpcNO_CLOSED;
135 return rpcNOT_SYNCED;
136 }
137
138 return rpcSUCCESS;
139}
140
141} // namespace RPC
142} // namespace ripple
143
144#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:41
@ NEEDS_NETWORK_CONNECTION
Definition Handler.h:40
@ NO_CONDITION
Definition Handler.h:39
@ NEEDS_CLOSED_LEDGER
Definition Handler.h:42
std::set< char const * > getHandlerNames()
Return names of all methods.
Definition Handler.cpp:318
Json::Value makeObjectValue(Value const &value, Json::StaticString const &field=jss::message)
Return a Json::objectValue with a single entry.
Definition Handler.h:65
static constexpr auto apiMaximumValidVersion
Definition ApiVersion.h:62
Handler const * getHandler(unsigned version, bool betaEnabled, std::string const &name)
Definition Handler.cpp:312
error_code_i conditionMet(Condition condition_required, T &context)
Definition Handler.h:80
static constexpr auto apiMinimumSupportedVersion
Definition ApiVersion.h:56
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:53
char const * name_
Definition Handler.h:50
Method< Json::Value > valueMethod_
Definition Handler.h:51
unsigned maxApiVer_
Definition Handler.h:56
unsigned minApiVer_
Definition Handler.h:55
Status represents the results of an operation that might fail.
Definition Status.h:40