rippled
Loading...
Searching...
No Matches
ReadView.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_LEDGER_READVIEW_H_INCLUDED
21#define RIPPLE_LEDGER_READVIEW_H_INCLUDED
22
23#include <xrpld/ledger/detail/ReadViewFwdRange.h>
24
25#include <xrpl/basics/chrono.h>
26#include <xrpl/beast/hash/uhash.h>
27#include <xrpl/protocol/Fees.h>
28#include <xrpl/protocol/IOUAmount.h>
29#include <xrpl/protocol/Indexes.h>
30#include <xrpl/protocol/LedgerHeader.h>
31#include <xrpl/protocol/Protocol.h>
32#include <xrpl/protocol/Rules.h>
33#include <xrpl/protocol/STAmount.h>
34#include <xrpl/protocol/STLedgerEntry.h>
35#include <xrpl/protocol/STTx.h>
36
37#include <cstdint>
38#include <optional>
39#include <unordered_set>
40
41namespace ripple {
42
43//------------------------------------------------------------------------------
44
52{
53public:
54 using tx_type =
56
58
60
61 struct sles_type : detail::ReadViewFwdRange<std::shared_ptr<SLE const>>
62 {
63 explicit sles_type(ReadView const& view);
65 begin() const;
67 end() const;
69 upper_bound(key_type const& key) const;
70 };
71
73 {
74 explicit txs_type(ReadView const& view);
75 bool
76 empty() const;
77 iterator
78 begin() const;
79 iterator
80 end() const;
81 };
82
83 virtual ~ReadView() = default;
84
86 operator=(ReadView&& other) = delete;
88 operator=(ReadView const& other) = delete;
89
90 ReadView() : sles(*this), txs(*this)
91 {
92 }
93
94 ReadView(ReadView const& other) : sles(*this), txs(*this)
95 {
96 }
97
98 ReadView(ReadView&& other) : sles(*this), txs(*this)
99 {
100 }
101
103 virtual LedgerInfo const&
104 info() const = 0;
105
107 virtual bool
108 open() const = 0;
109
113 {
114 return info().parentCloseTime;
115 }
116
119 seq() const
120 {
121 return info().seq;
122 }
123
125 virtual Fees const&
126 fees() const = 0;
127
129 virtual Rules const&
130 rules() const = 0;
131
139 virtual bool
140 exists(Keylet const& k) const = 0;
141
154 key_type const& key,
155 std::optional<key_type> const& last = std::nullopt) const = 0;
156
171 read(Keylet const& k) const = 0;
172
173 // Accounts in a payment are not allowed to use assets acquired during that
174 // payment. The PaymentSandbox tracks the debits, credits, and owner count
175 // changes that accounts make during a payment. `balanceHook` adjusts
176 // balances so newly acquired assets are not counted toward the balance.
177 // This is required to support PaymentSandbox.
178 virtual STAmount
180 AccountID const& account,
181 AccountID const& issuer,
182 STAmount const& amount) const
183 {
184 return amount;
185 }
186
187 // Accounts in a payment are not allowed to use assets acquired during that
188 // payment. The PaymentSandbox tracks the debits, credits, and owner count
189 // changes that accounts make during a payment. `ownerCountHook` adjusts the
190 // ownerCount so it returns the max value of the ownerCount so far.
191 // This is required to support PaymentSandbox.
192 virtual std::uint32_t
193 ownerCountHook(AccountID const& account, std::uint32_t count) const
194 {
195 return count;
196 }
197
198 // used by the implementation
200 slesBegin() const = 0;
201
202 // used by the implementation
204 slesEnd() const = 0;
205
206 // used by the implementation
208 slesUpperBound(key_type const& key) const = 0;
209
210 // used by the implementation
212 txsBegin() const = 0;
213
214 // used by the implementation
216 txsEnd() const = 0;
217
223 virtual bool
224 txExists(key_type const& key) const = 0;
225
234 virtual tx_type
235 txRead(key_type const& key) const = 0;
236
237 //
238 // Memberspaces
239 //
240
247
248 // The range of transactions
250};
251
252//------------------------------------------------------------------------------
253
256{
257public:
259
262
268 digest(key_type const& key) const = 0;
269};
270
271//------------------------------------------------------------------------------
272
273Rules
275
276Rules
278 DigestAwareReadView const& ledger,
279 std::unordered_set<uint256, beast::uhash<>> const& presets);
280
281} // namespace ripple
282
283#include <xrpld/ledger/detail/ReadViewFwdRange.ipp>
284
285#endif
ReadView that associates keys with digests.
Definition: ReadView.h:256
virtual std::optional< digest_type > digest(key_type const &key) const =0
Return the digest associated with the key.
DigestAwareReadView(DigestAwareReadView const &)=default
A view into a ledger.
Definition: ReadView.h:52
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
ReadView(ReadView &&other)
Definition: ReadView.h:98
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
Definition: ReadView.h:112
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
virtual std::unique_ptr< sles_type::iter_base > slesUpperBound(key_type const &key) const =0
virtual std::unique_ptr< txs_type::iter_base > txsBegin() const =0
ReadView & operator=(ReadView &&other)=delete
virtual ~ReadView()=default
virtual std::unique_ptr< sles_type::iter_base > slesEnd() const =0
ReadView & operator=(ReadView const &other)=delete
txs_type txs
Definition: ReadView.h:249
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
Definition: ReadView.h:193
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition: ReadView.h:179
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition: ReadView.h:119
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual std::unique_ptr< txs_type::iter_base > txsEnd() const =0
virtual std::unique_ptr< sles_type::iter_base > slesBegin() const =0
ReadView(ReadView const &other)
Definition: ReadView.h:94
virtual tx_type txRead(key_type const &key) const =0
Read a transaction from the tx map.
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
sles_type sles
Iterable range of ledger state items.
Definition: ReadView.h:246
Rules controlling protocol behavior.
Definition: Rules.h:38
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 256 > uint256
Definition: base_uint.h:558
@ current
This was a new validation and was added.
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition: ReadView.cpp:69
Reflects the fee settings for a particular ledger.
Definition: protocol/Fees.h:33
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
Information about the notional ledger backing the view.
Definition: LedgerHeader.h:34
NetClock::time_point parentCloseTime
Definition: LedgerHeader.h:42
iterator upper_bound(key_type const &key) const
Definition: ReadView.cpp:41
iterator end() const
Definition: ReadView.cpp:35
iterator begin() const
Definition: ReadView.cpp:29
iterator end() const
Definition: ReadView.cpp:63
iterator begin() const
Definition: ReadView.cpp:57