rippled
Loading...
Searching...
No Matches
ReadView.h
1#pragma once
2
3#include <xrpl/basics/chrono.h>
4#include <xrpl/beast/hash/uhash.h>
5#include <xrpl/ledger/detail/ReadViewFwdRange.h>
6#include <xrpl/protocol/Fees.h>
7#include <xrpl/protocol/IOUAmount.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/LedgerHeader.h>
10#include <xrpl/protocol/Protocol.h>
11#include <xrpl/protocol/Rules.h>
12#include <xrpl/protocol/STAmount.h>
13#include <xrpl/protocol/STLedgerEntry.h>
14#include <xrpl/protocol/STTx.h>
15
16#include <cstdint>
17#include <optional>
18#include <unordered_set>
19
20namespace xrpl {
21
22//------------------------------------------------------------------------------
23
31{
32public:
34
36
38
39 struct sles_type : detail::ReadViewFwdRange<std::shared_ptr<SLE const>>
40 {
41 explicit sles_type(ReadView const& view);
43 begin() const;
45 end() const;
47 upper_bound(key_type const& key) const;
48 };
49
51 {
52 explicit txs_type(ReadView const& view);
53 bool
54 empty() const;
55 iterator
56 begin() const;
57 iterator
58 end() const;
59 };
60
61 virtual ~ReadView() = default;
62
64 operator=(ReadView&& other) = delete;
66 operator=(ReadView const& other) = delete;
67
68 ReadView() : sles(*this), txs(*this)
69 {
70 }
71
72 ReadView(ReadView const& other) : sles(*this), txs(*this)
73 {
74 }
75
76 ReadView(ReadView&& other) : sles(*this), txs(*this)
77 {
78 }
79
81 virtual LedgerHeader const&
82 header() const = 0;
83
85 virtual bool
86 open() const = 0;
87
91 {
92 return header().parentCloseTime;
93 }
94
97 seq() const
98 {
99 return header().seq;
100 }
101
103 virtual Fees const&
104 fees() const = 0;
105
107 virtual Rules const&
108 rules() const = 0;
109
117 virtual bool
118 exists(Keylet const& k) const = 0;
119
131 succ(key_type const& key, std::optional<key_type> const& last = std::nullopt) const = 0;
132
147 read(Keylet const& k) const = 0;
148
149 // Accounts in a payment are not allowed to use assets acquired during that
150 // payment. The PaymentSandbox tracks the debits, credits, and owner count
151 // changes that accounts make during a payment. `balanceHook` adjusts
152 // balances so newly acquired assets are not counted toward the balance.
153 // This is required to support PaymentSandbox.
154 virtual STAmount
155 balanceHook(AccountID const& account, AccountID const& issuer, STAmount const& amount) const
156 {
157 return amount;
158 }
159
160 // Accounts in a payment are not allowed to use assets acquired during that
161 // payment. The PaymentSandbox tracks the debits, credits, and owner count
162 // changes that accounts make during a payment. `ownerCountHook` adjusts the
163 // ownerCount so it returns the max value of the ownerCount so far.
164 // This is required to support PaymentSandbox.
165 virtual std::uint32_t
166 ownerCountHook(AccountID const& account, std::uint32_t count) const
167 {
168 return count;
169 }
170
171 // used by the implementation
173 slesBegin() const = 0;
174
175 // used by the implementation
177 slesEnd() const = 0;
178
179 // used by the implementation
181 slesUpperBound(key_type const& key) const = 0;
182
183 // used by the implementation
185 txsBegin() const = 0;
186
187 // used by the implementation
189 txsEnd() const = 0;
190
196 virtual bool
197 txExists(key_type const& key) const = 0;
198
207 virtual tx_type
208 txRead(key_type const& key) const = 0;
209
210 //
211 // Memberspaces
212 //
213
220
221 // The range of transactions
223};
224
225//------------------------------------------------------------------------------
226
229{
230public:
232
235
241 digest(key_type const& key) const = 0;
242};
243
244//------------------------------------------------------------------------------
245
246Rules
248
249Rules
251
252} // namespace xrpl
253
254#include <xrpl/ledger/detail/ReadViewFwdRange.ipp>
ReadView that associates keys with digests.
Definition ReadView.h:229
DigestAwareReadView(DigestAwareReadView const &)=default
virtual std::optional< digest_type > digest(key_type const &key) const =0
Return the digest associated with the key.
A view into a ledger.
Definition ReadView.h:31
ReadView & operator=(ReadView &&other)=delete
virtual Rules const & rules() const =0
Returns the tx processing rules.
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
Definition ReadView.h:90
virtual std::unique_ptr< txs_type::iter_base > txsBegin() const =0
virtual ~ReadView()=default
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.
virtual std::unique_ptr< txs_type::iter_base > txsEnd() const =0
virtual std::unique_ptr< sles_type::iter_base > slesUpperBound(key_type const &key) const =0
virtual tx_type txRead(key_type const &key) const =0
Read a transaction from the tx map.
ReadView(ReadView const &other)
Definition ReadView.h:72
ReadView(ReadView &&other)
Definition ReadView.h:76
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
ReadView & operator=(ReadView const &other)=delete
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition ReadView.h:155
virtual bool open() const =0
Returns true if this reflects an open ledger.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition ReadView.h:97
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
Definition ReadView.h:166
txs_type txs
Definition ReadView.h:222
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.
sles_type sles
Iterable range of ledger state items.
Definition ReadView.h:219
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual std::unique_ptr< sles_type::iter_base > slesBegin() const =0
virtual std::unique_ptr< sles_type::iter_base > slesEnd() const =0
Rules controlling protocol behavior.
Definition Rules.h:18
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition ReadView.cpp:50
@ current
This was a new validation and was added.
base_uint< 256 > uint256
Definition base_uint.h:526
Reflects the fee settings for a particular ledger.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
Information about the notional ledger backing the view.
NetClock::time_point parentCloseTime
iterator begin() const
Definition ReadView.cpp:10
iterator end() const
Definition ReadView.cpp:16
iterator upper_bound(key_type const &key) const
Definition ReadView.cpp:22
iterator begin() const
Definition ReadView.cpp:38
iterator end() const
Definition ReadView.cpp:44