rippled
Loading...
Searching...
No Matches
LedgerHandler.h
1#ifndef XRPL_RPC_HANDLERS_LEDGER_H_INCLUDED
2#define XRPL_RPC_HANDLERS_LEDGER_H_INCLUDED
3
4#include <xrpld/app/ledger/LedgerMaster.h>
5#include <xrpld/app/ledger/LedgerToJson.h>
6#include <xrpld/app/main/Application.h>
7#include <xrpld/rpc/Context.h>
8#include <xrpld/rpc/Role.h>
9#include <xrpld/rpc/Status.h>
10#include <xrpld/rpc/detail/Handler.h>
11
12#include <xrpl/json/Object.h>
13#include <xrpl/ledger/ReadView.h>
14#include <xrpl/protocol/ApiVersion.h>
15#include <xrpl/protocol/jss.h>
16
17namespace Json {
18class Object;
19}
20
21namespace ripple {
22namespace RPC {
23
24struct JsonContext;
25
26// ledger [id|index|current|closed] [full]
27// {
28// ledger: 'current' | 'closed' | <uint256> | <number>, // optional
29// full: true | false // optional, defaults to false.
30// }
31
33{
34public:
35 explicit LedgerHandler(JsonContext&);
36
37 Status
38 check();
39
40 template <class Object>
41 void
42 writeResult(Object&);
43
44 static constexpr char name[] = "ledger";
45
46 static constexpr unsigned minApiVer = RPC::apiMinimumSupportedVersion;
47
48 static constexpr unsigned maxApiVer = RPC::apiMaximumValidVersion;
49
50 static constexpr Role role = Role::USER;
51
52 static constexpr Condition condition = NO_CONDITION;
53
54private:
59 int options_ = 0;
60};
61
64//
65// Implementation.
66
67template <class Object>
68void
70{
71 if (ledger_)
72 {
73 Json::copyFrom(value, result_);
75 }
76 else
77 {
78 auto& master = context_.app.getLedgerMaster();
79 {
80 auto&& closed = Json::addObject(value, jss::closed);
81 addJson(closed, {*master.getClosedLedger(), &context_, 0});
82 }
83 {
84 auto&& open = Json::addObject(value, jss::open);
85 addJson(open, {*master.getCurrentLedger(), &context_, 0});
86 }
87 }
88
90 if (context_.params.isMember(jss::type))
91 {
93 w[jss::id] = warnRPC_FIELDS_DEPRECATED;
94 w[jss::message] =
95 "Some fields from your request are deprecated. Please check the "
96 "documentation at "
97 "https://xrpl.org/docs/references/http-websocket-apis/ "
98 "and update your request. Field `type` is deprecated.";
99 }
100
101 if (warnings.size())
102 value[jss::warnings] = std::move(warnings);
103}
104
105} // namespace RPC
106} // namespace ripple
107
108#endif
Represents a JSON value.
Definition json_value.h:130
Value & append(Value const &value)
Append value to array at the end.
bool isMember(char const *key) const
Return true if the object has a member named key.
virtual LedgerMaster & getLedgerMaster()=0
static constexpr unsigned maxApiVer
static constexpr Condition condition
static constexpr unsigned minApiVer
std::shared_ptr< ReadView const > ledger_
static constexpr char name[]
std::vector< TxQ::TxDetails > queueTxs_
static constexpr Role role
JSON (JavaScript Object Notation).
Definition json_errors.h:6
@ arrayValue
array value (ordered list)
Definition json_value.h:25
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:26
Json::Value & addObject(Json::Value &, Json::StaticString const &key)
Add a new subobject at a named key in a Json object.
Definition Object.h:408
void copyFrom(Json::Value &to, Json::Value const &from)
Copy all the keys and values from one object into another.
Definition Object.cpp:213
@ NO_CONDITION
Definition Handler.h:21
static constexpr auto apiMaximumValidVersion
Definition ApiVersion.h:48
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
@ warnRPC_FIELDS_DEPRECATED
Definition ErrorCodes.h:158
void addJson(Json::Value &json, LedgerFill const &fill)
Given a Ledger and options, fill a Json::Object or Json::Value with a description of the ledger.
@ open
We haven't closed our ledger yet, but others might have.
Role
Indicates the level of administrative permission to grant.
Definition Role.h:25
Application & app
Definition Context.h:22
Status represents the results of an operation that might fail.
Definition Status.h:21