rippled
Loading...
Searching...
No Matches
ReadView.h
1#ifndef XRPL_LEDGER_READVIEW_H_INCLUDED
2#define XRPL_LEDGER_READVIEW_H_INCLUDED
3
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/hash/uhash.h>
6#include <xrpl/ledger/detail/ReadViewFwdRange.h>
7#include <xrpl/protocol/Fees.h>
8#include <xrpl/protocol/IOUAmount.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/LedgerHeader.h>
11#include <xrpl/protocol/Protocol.h>
12#include <xrpl/protocol/Rules.h>
13#include <xrpl/protocol/STAmount.h>
14#include <xrpl/protocol/STLedgerEntry.h>
15#include <xrpl/protocol/STTx.h>
16
17#include <cstdint>
18#include <optional>
19#include <unordered_set>
20
21namespace ripple {
22
23//------------------------------------------------------------------------------
24
32{
33public:
34 using tx_type =
36
38
40
41 struct sles_type : detail::ReadViewFwdRange<std::shared_ptr<SLE const>>
42 {
43 explicit sles_type(ReadView const& view);
45 begin() const;
47 end() const;
49 upper_bound(key_type const& key) const;
50 };
51
53 {
54 explicit txs_type(ReadView const& view);
55 bool
56 empty() const;
57 iterator
58 begin() const;
59 iterator
60 end() const;
61 };
62
63 virtual ~ReadView() = default;
64
66 operator=(ReadView&& other) = delete;
68 operator=(ReadView const& other) = delete;
69
70 ReadView() : sles(*this), txs(*this)
71 {
72 }
73
74 ReadView(ReadView const& other) : sles(*this), txs(*this)
75 {
76 }
77
78 ReadView(ReadView&& other) : sles(*this), txs(*this)
79 {
80 }
81
83 virtual LedgerInfo const&
84 info() const = 0;
85
87 virtual bool
88 open() const = 0;
89
93 {
94 return info().parentCloseTime;
95 }
96
99 seq() const
100 {
101 return info().seq;
102 }
103
105 virtual Fees const&
106 fees() const = 0;
107
109 virtual Rules const&
110 rules() const = 0;
111
119 virtual bool
120 exists(Keylet const& k) const = 0;
121
134 key_type const& key,
135 std::optional<key_type> const& last = std::nullopt) const = 0;
136
151 read(Keylet const& k) const = 0;
152
153 // Accounts in a payment are not allowed to use assets acquired during that
154 // payment. The PaymentSandbox tracks the debits, credits, and owner count
155 // changes that accounts make during a payment. `balanceHook` adjusts
156 // balances so newly acquired assets are not counted toward the balance.
157 // This is required to support PaymentSandbox.
158 virtual STAmount
160 AccountID const& account,
161 AccountID const& issuer,
162 STAmount const& amount) const
163 {
164 return amount;
165 }
166
167 // Accounts in a payment are not allowed to use assets acquired during that
168 // payment. The PaymentSandbox tracks the debits, credits, and owner count
169 // changes that accounts make during a payment. `ownerCountHook` adjusts the
170 // ownerCount so it returns the max value of the ownerCount so far.
171 // This is required to support PaymentSandbox.
172 virtual std::uint32_t
173 ownerCountHook(AccountID const& account, std::uint32_t count) const
174 {
175 return count;
176 }
177
178 // used by the implementation
180 slesBegin() const = 0;
181
182 // used by the implementation
184 slesEnd() const = 0;
185
186 // used by the implementation
188 slesUpperBound(key_type const& key) const = 0;
189
190 // used by the implementation
192 txsBegin() const = 0;
193
194 // used by the implementation
196 txsEnd() const = 0;
197
203 virtual bool
204 txExists(key_type const& key) const = 0;
205
214 virtual tx_type
215 txRead(key_type const& key) const = 0;
216
217 //
218 // Memberspaces
219 //
220
227
228 // The range of transactions
230};
231
232//------------------------------------------------------------------------------
233
236{
237public:
239
242
248 digest(key_type const& key) const = 0;
249};
250
251//------------------------------------------------------------------------------
252
253Rules
255
256Rules
258 DigestAwareReadView const& ledger,
259 std::unordered_set<uint256, beast::uhash<>> const& presets);
260
261} // namespace ripple
262
263#include <xrpl/ledger/detail/ReadViewFwdRange.ipp>
264
265#endif
ReadView that associates keys with digests.
Definition ReadView.h:236
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:32
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:78
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
Definition ReadView.h:92
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
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
Definition ReadView.h:173
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition ReadView.h:159
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:99
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:74
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:226
Rules controlling protocol behavior.
Definition Rules.h:19
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
base_uint< 256 > uint256
Definition base_uint.h:539
@ current
This was a new validation and was added.
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition ReadView.cpp:50
Reflects the fee settings for a particular ledger.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
Information about the notional ledger backing the view.
NetClock::time_point parentCloseTime
iterator upper_bound(key_type const &key) const
Definition ReadView.cpp:22
iterator begin() const
Definition ReadView.cpp:10
iterator end() const
Definition ReadView.cpp:44
iterator begin() const
Definition ReadView.cpp:38