rippled
Loading...
Searching...
No Matches
LedgerHandler.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_HANDLERS_LEDGER_H_INCLUDED
21#define RIPPLE_RPC_HANDLERS_LEDGER_H_INCLUDED
22
23#include <xrpld/app/ledger/LedgerMaster.h>
24#include <xrpld/app/ledger/LedgerToJson.h>
25#include <xrpld/app/main/Application.h>
26#include <xrpld/rpc/Context.h>
27#include <xrpld/rpc/Role.h>
28#include <xrpld/rpc/Status.h>
29#include <xrpld/rpc/detail/Handler.h>
30#include <xrpld/rpc/detail/RPCHelpers.h>
31
32#include <xrpl/json/Object.h>
33#include <xrpl/ledger/ReadView.h>
34#include <xrpl/protocol/jss.h>
35
36namespace Json {
37class Object;
38}
39
40namespace ripple {
41namespace RPC {
42
43struct JsonContext;
44
45// ledger [id|index|current|closed] [full]
46// {
47// ledger: 'current' | 'closed' | <uint256> | <number>, // optional
48// full: true | false // optional, defaults to false.
49// }
50
52{
53public:
54 explicit LedgerHandler(JsonContext&);
55
56 Status
57 check();
58
59 template <class Object>
60 void
61 writeResult(Object&);
62
63 static constexpr char name[] = "ledger";
64
65 static constexpr unsigned minApiVer = RPC::apiMinimumSupportedVersion;
66
67 static constexpr unsigned maxApiVer = RPC::apiMaximumValidVersion;
68
69 static constexpr Role role = Role::USER;
70
71 static constexpr Condition condition = NO_CONDITION;
72
73private:
78 int options_ = 0;
79};
80
83//
84// Implementation.
85
86template <class Object>
87void
89{
90 if (ledger_)
91 {
92 Json::copyFrom(value, result_);
94 }
95 else
96 {
97 auto& master = context_.app.getLedgerMaster();
98 {
99 auto&& closed = Json::addObject(value, jss::closed);
100 addJson(closed, {*master.getClosedLedger(), &context_, 0});
101 }
102 {
103 auto&& open = Json::addObject(value, jss::open);
104 addJson(open, {*master.getCurrentLedger(), &context_, 0});
105 }
106 }
107
109 if (context_.params.isMember(jss::type))
110 {
111 Json::Value& w = warnings.append(Json::objectValue);
112 w[jss::id] = warnRPC_FIELDS_DEPRECATED;
113 w[jss::message] =
114 "Some fields from your request are deprecated. Please check the "
115 "documentation at "
116 "https://xrpl.org/docs/references/http-websocket-apis/ "
117 "and update your request. Field `type` is deprecated.";
118 }
119
120 if (warnings.size())
121 value[jss::warnings] = std::move(warnings);
122}
123
124} // namespace RPC
125} // namespace ripple
126
127#endif
Represents a JSON value.
Definition json_value.h:149
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:25
@ arrayValue
array value (ordered list)
Definition json_value.h:44
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
Json::Value & addObject(Json::Value &, Json::StaticString const &key)
Add a new subobject at a named key in a Json object.
Definition Object.h:427
void copyFrom(Json::Value &to, Json::Value const &from)
Copy all the keys and values from one object into another.
Definition Object.cpp:232
@ NO_CONDITION
Definition Handler.h:39
static constexpr auto apiMaximumValidVersion
Definition ApiVersion.h:62
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
@ warnRPC_FIELDS_DEPRECATED
Definition ErrorCodes.h:177
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:44
Application & app
Definition Context.h:41
Status represents the results of an operation that might fail.
Definition Status.h:40