xrpld
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 SlesType : detail::ReadViewFwdRange<SLE::const_pointer>
40 {
41 explicit SlesType(ReadView const& view);
42 [[nodiscard]] Iterator
43 begin() const;
44 [[nodiscard]] Iterator
45 end() const;
46 [[nodiscard]] Iterator
47 upperBound(key_type const& key) const;
48 };
49
51 {
52 explicit TxsType(ReadView const& view);
53 [[nodiscard]] bool
54 empty() const;
55 [[nodiscard]] Iterator
56 begin() const;
57 [[nodiscard]] 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 [[nodiscard]] virtual LedgerHeader const&
82 header() const = 0;
83
85 [[nodiscard]] virtual bool
86 open() const = 0;
87
89 [[nodiscard]] NetClock::time_point
91 {
92 return header().parentCloseTime;
93 }
94
96 [[nodiscard]] LedgerIndex
97 seq() const
98 {
99 return header().seq;
100 }
101
103 [[nodiscard]] virtual Fees const&
104 fees() const = 0;
105
107 [[nodiscard]] virtual Rules const&
108 rules() const = 0;
109
117 [[nodiscard]] virtual bool
118 exists(Keylet const& k) const = 0;
119
130 [[nodiscard]] virtual std::optional<key_type>
131 succ(key_type const& key, std::optional<key_type> const& last = std::nullopt) const = 0;
132
146 [[nodiscard]] virtual SLE::const_pointer
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. `balanceHookIOU` adjusts
152 // balances so newly acquired assets are not counted toward the balance.
153 // This is required to support PaymentSandbox.
154 [[nodiscard]] virtual STAmount
155 balanceHookIOU(AccountID const& account, AccountID const& issuer, STAmount const& amount) const
156 {
157 XRPL_ASSERT(amount.holds<Issue>(), "balanceHookIOU: amount is for Issue");
158
159 return amount;
160 }
161
162 // balanceHookMPT adjusts balances so newly acquired assets are not counted
163 // toward the balance.
164 [[nodiscard]] virtual STAmount
165 balanceHookMPT(AccountID const& account, MPTIssue const& issue, std::int64_t amount) const
166 {
167 return STAmount{issue, amount};
168 }
169
170 // An offer owned by an issuer and selling MPT is limited by the issuer's
171 // funds available to issue, which are originally available funds less
172 // already self sold MPT amounts (MPT sell offer). This hook is used
173 // by issuerFundsToSelfIssue() function.
174 [[nodiscard]] virtual STAmount
176 {
177 return STAmount{issue, amount};
178 }
179
180 // Accounts in a payment are not allowed to use assets acquired during that
181 // payment. The PaymentSandbox tracks the debits, credits, and owner count
182 // changes that accounts make during a payment. `ownerCountHook` adjusts the
183 // ownerCount so it returns the max value of the ownerCount so far.
184 // This is required to support PaymentSandbox.
185 [[nodiscard]] virtual std::uint32_t
186 ownerCountHook(AccountID const& account, std::uint32_t count) const
187 {
188 return count;
189 }
190
191 // used by the implementation
192 [[nodiscard]] virtual std::unique_ptr<SlesType::iter_base>
193 slesBegin() const = 0;
194
195 // used by the implementation
196 [[nodiscard]] virtual std::unique_ptr<SlesType::iter_base>
197 slesEnd() const = 0;
198
199 // used by the implementation
200 [[nodiscard]] virtual std::unique_ptr<SlesType::iter_base>
201 slesUpperBound(key_type const& key) const = 0;
202
203 // used by the implementation
204 [[nodiscard]] virtual std::unique_ptr<TxsType::iter_base>
205 txsBegin() const = 0;
206
207 // used by the implementation
208 [[nodiscard]] virtual std::unique_ptr<TxsType::iter_base>
209 txsEnd() const = 0;
210
216 [[nodiscard]] virtual bool
217 txExists(key_type const& key) const = 0;
218
227 [[nodiscard]] virtual tx_type
228 txRead(key_type const& key) const = 0;
229
230 //
231 // Memberspaces
232 //
233
240
241 // The range of transactions
243};
244
245//------------------------------------------------------------------------------
246
249{
250public:
252
255
260 [[nodiscard]] virtual std::optional<digest_type>
261 digest(key_type const& key) const = 0;
262};
263
264//------------------------------------------------------------------------------
265
266Rules
267makeRulesGivenLedger(DigestAwareReadView const& ledger, Rules const& current);
268
269Rules
271 DigestAwareReadView const& ledger,
272 std::unordered_set<uint256, beast::Uhash<>> const& presets);
273
274} // namespace xrpl
275
276#include <xrpl/ledger/detail/ReadViewFwdRange.ipp>
ReadView that associates keys with digests.
Definition ReadView.h:249
DigestAwareReadView(DigestAwareReadView const &)=default
virtual std::optional< digest_type > digest(key_type const &key) const =0
Return the digest associated with the key.
A currency issued by an account.
Definition Issue.h:13
std::chrono::time_point< NetClock > time_point
Definition chrono.h:46
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 ~ReadView()=default
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:33
virtual std::unique_ptr< TxsType::iter_base > txsBegin() const =0
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
TxsType txs
Definition ReadView.h:242
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual STAmount balanceHookMPT(AccountID const &account, MPTIssue const &issue, std::int64_t amount) const
Definition ReadView.h:165
virtual tx_type txRead(key_type const &key) const =0
Read a transaction from the tx map.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
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 std::unique_ptr< TxsType::iter_base > txsEnd() const =0
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
virtual bool open() const =0
Returns true if this reflects an open ledger.
SlesType sles
Iterable range of ledger state items.
Definition ReadView.h:239
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:186
virtual std::unique_ptr< SlesType::iter_base > slesBegin() const =0
virtual std::unique_ptr< SlesType::iter_base > slesUpperBound(key_type const &key) const =0
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.
uint256 key_type
Definition ReadView.h:35
virtual STAmount balanceHookSelfIssueMPT(MPTIssue const &issue, std::int64_t amount) const
Definition ReadView.h:175
virtual std::unique_ptr< SlesType::iter_base > slesEnd() const =0
SLE::const_pointer mapped_type
Definition ReadView.h:37
virtual STAmount balanceHookIOU(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition ReadView.h:155
Rules controlling protocol behavior.
Definition Rules.h:33
constexpr bool holds() const noexcept
Definition STAmount.h:460
std::shared_ptr< STLedgerEntry const > const_pointer
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::uint32_t LedgerIndex
A ledger index.
Definition Protocol.h:259
Rules makeRulesGivenLedger(DigestAwareReadView const &ledger, Rules const &current)
Definition ReadView.cpp:61
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
BaseUInt< 256 > uint256
Definition base_uint.h:562
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:21
Iterator upperBound(key_type const &key) const
Definition ReadView.cpp:33
Iterator end() const
Definition ReadView.cpp:27
SlesType(ReadView const &view)
Definition ReadView.cpp:16
Iterator end() const
Definition ReadView.cpp:55
Iterator begin() const
Definition ReadView.cpp:49
TxsType(ReadView const &view)
Definition ReadView.cpp:38