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/ledger/ReadView.h>
27#include <xrpld/rpc/Context.h>
28#include <xrpld/rpc/Role.h>
29#include <xrpld/rpc/Status.h>
30#include <xrpld/rpc/detail/Handler.h>
31#include <xrpld/rpc/detail/RPCHelpers.h>
32
33#include <xrpl/json/Object.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;
80};
81
84//
85// Implementation.
86
87template <class Object>
88void
90{
91 if (ledger_)
92 {
93 Json::copyFrom(value, result_);
95 }
96 else
97 {
98 auto& master = context_.app.getLedgerMaster();
99 {
100 auto&& closed = Json::addObject(value, jss::closed);
101 addJson(closed, {*master.getClosedLedger(), &context_, 0});
102 }
103 {
104 auto&& open = Json::addObject(value, jss::open);
105 addJson(open, {*master.getCurrentLedger(), &context_, 0});
106 }
107 }
108}
109
110} // namespace RPC
111} // namespace ripple
112
113#endif
Represents a JSON value.
Definition: json_value.h:150
virtual LedgerMaster & getLedgerMaster()=0
static constexpr unsigned maxApiVer
Definition: LedgerHandler.h:67
static constexpr unsigned minApiVer
Definition: LedgerHandler.h:65
std::shared_ptr< ReadView const > ledger_
Definition: LedgerHandler.h:75
static constexpr char name[]
Definition: LedgerHandler.h:63
void writeResult(Object &)
Definition: LedgerHandler.h:89
std::vector< TxQ::TxDetails > queueTxs_
Definition: LedgerHandler.h:76
static constexpr Role role
Definition: LedgerHandler.h:69
JSON (JavaScript Object Notation).
Definition: json_errors.h:25
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:63
static constexpr auto apiMinimumSupportedVersion
Definition: ApiVersion.h:57
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
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.
LedgerEntryType
Identifiers for on-ledger objects.
Definition: LedgerFormats.h:54
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