xrpld
Loading...
Searching...
No Matches
ReadView.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/hash/uhash.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/ledger/OwnerCounts.h>
8#include <xrpl/ledger/detail/ReadViewFwdRange.h>
9#include <xrpl/protocol/AccountID.h>
10#include <xrpl/protocol/Fees.h>
11#include <xrpl/protocol/Issue.h> // IWYU pragma: keep
12#include <xrpl/protocol/Keylet.h>
13#include <xrpl/protocol/LedgerHeader.h>
14#include <xrpl/protocol/MPTIssue.h>
15#include <xrpl/protocol/Protocol.h>
16#include <xrpl/protocol/Rules.h>
17#include <xrpl/protocol/SField.h>
18#include <xrpl/protocol/STAmount.h>
19#include <xrpl/protocol/STLedgerEntry.h>
20#include <xrpl/protocol/STObject.h>
21#include <xrpl/protocol/STTx.h>
22
23#include <cstdint>
24#include <memory>
25#include <optional>
26#include <unordered_set>
27#include <utility>
28
29namespace xrpl {
30
31//------------------------------------------------------------------------------
32
41{
42public:
44
46
48
49 struct SlesType : detail::ReadViewFwdRange<SLE::const_pointer>
50 {
51 explicit SlesType(ReadView const& view);
52 [[nodiscard]] Iterator
53 begin() const;
54 [[nodiscard]] Iterator
55 end() const;
56 [[nodiscard]] Iterator
57 upperBound(key_type const& key) const;
58 };
59
61 {
62 explicit TxsType(ReadView const& view);
63 [[nodiscard]] bool
64 empty() const;
65 [[nodiscard]] Iterator
66 begin() const;
67 [[nodiscard]] Iterator
68 end() const;
69 };
70
71 virtual ~ReadView() = default;
72
74 operator=(ReadView&& other) = delete;
76 operator=(ReadView const& other) = delete;
77
78 ReadView() : sles(*this), txs(*this)
79 {
80 }
81
82 ReadView(ReadView const& other) : sles(*this), txs(*this)
83 {
84 }
85
86 ReadView(ReadView&& other) : sles(*this), txs(*this)
87 {
88 }
89
93 [[nodiscard]] virtual LedgerHeader const&
94 header() const = 0;
95
99 [[nodiscard]] virtual bool
100 open() const = 0;
101
105 [[nodiscard]] NetClock::time_point
107 {
108 return header().parentCloseTime;
109 }
110
114 [[nodiscard]] LedgerIndex
115 seq() const
116 {
117 return header().seq;
118 }
119
123 [[nodiscard]] virtual Fees const&
124 fees() const = 0;
125
129 [[nodiscard]] virtual Rules const&
130 rules() const = 0;
131
140 [[nodiscard]] virtual bool
141 exists(Keylet const& k) const = 0;
142
154 [[nodiscard]] virtual std::optional<key_type>
155 succ(key_type const& key, std::optional<key_type> const& last = std::nullopt) const = 0;
156
171 [[nodiscard]] virtual SLE::const_pointer
172 read(Keylet const& k) const = 0;
173
174 // Accounts in a payment are not allowed to use assets acquired during that
175 // payment. The PaymentSandbox tracks the debits, credits, and owner count
176 // changes that accounts make during a payment. `balanceHookIOU` adjusts
177 // balances so newly acquired assets are not counted toward the balance.
178 // This is required to support PaymentSandbox.
179 [[nodiscard]] virtual STAmount
180 balanceHookIOU(AccountID const& account, AccountID const& issuer, STAmount const& amount) const
181 {
182 XRPL_ASSERT(amount.holds<Issue>(), "balanceHookIOU: amount is for Issue");
183
184 return amount;
185 }
186
187 // balanceHookMPT adjusts balances so newly acquired assets are not counted
188 // toward the balance.
189 [[nodiscard]] virtual STAmount
190 balanceHookMPT(AccountID const& account, MPTIssue const& issue, std::int64_t amount) const
191 {
192 return STAmount{issue, amount};
193 }
194
195 // An offer owned by an issuer and selling MPT is limited by the issuer's
196 // funds available to issue, which are originally available funds less
197 // already self sold MPT amounts (MPT sell offer). This hook is used
198 // by issuerFundsToSelfIssue() function.
199 [[nodiscard]] virtual STAmount
201 {
202 return STAmount{issue, amount};
203 }
204
205 // Accounts in a payment are not allowed to use assets acquired during that
206 // payment. The PaymentSandbox tracks the debits, credits, and owner count
207 // changes that accounts make during a payment. `ownerCountHook` adjusts the
208 // ownerCount so it returns the max value of the ownerCount so far.
209 // This is required to support PaymentSandbox.
210 [[nodiscard]] virtual OwnerCounts
211 ownerCountHook(AccountID const& account, OwnerCounts const& count) const
212 {
213 return count;
214 }
215
216 // used by the implementation
217 [[nodiscard]] virtual std::unique_ptr<SlesType::iter_base>
218 slesBegin() const = 0;
219
220 // used by the implementation
221 [[nodiscard]] virtual std::unique_ptr<SlesType::iter_base>
222 slesEnd() const = 0;
223
224 // used by the implementation
225 [[nodiscard]] virtual std::unique_ptr<SlesType::iter_base>
226 slesUpperBound(key_type const& key) const = 0;
227
228 // used by the implementation
229 [[nodiscard]] virtual std::unique_ptr<TxsType::iter_base>
230 txsBegin() const = 0;
231
232 // used by the implementation
233 [[nodiscard]] virtual std::unique_ptr<TxsType::iter_base>
234 txsEnd() const = 0;
235
242 [[nodiscard]] virtual bool
243 txExists(key_type const& key) const = 0;
244
254 [[nodiscard]] virtual tx_type
255 txRead(key_type const& key) const = 0;
256
257 //
258 // Memberspaces
259 //
260
268
269 // The range of transactions
271};
272
273//------------------------------------------------------------------------------
274
279{
280public:
282
285
291 [[nodiscard]] virtual std::optional<digest_type>
292 digest(key_type const& key) const = 0;
293};
294
295//------------------------------------------------------------------------------
296
297Rules
298makeRulesGivenLedger(DigestAwareReadView const& ledger, Rules const& current);
299
300Rules
302 DigestAwareReadView const& ledger,
303 std::unordered_set<uint256, beast::Uhash<>> const& presets);
304
305} // namespace xrpl
306
307#include <xrpl/ledger/detail/ReadViewFwdRange.ipp>
ReadView that associates keys with digests.
Definition ReadView.h:279
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:18
std::chrono::time_point< NetClock > time_point
Definition chrono.h:48
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:106
virtual ~ReadView()=default
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:43
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:270
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:190
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:82
virtual OwnerCounts ownerCountHook(AccountID const &account, OwnerCounts const &count) const
Definition ReadView.h:211
ReadView(ReadView &&other)
Definition ReadView.h:86
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:267
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition ReadView.h:115
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:45
virtual STAmount balanceHookSelfIssueMPT(MPTIssue const &issue, std::int64_t amount) const
Definition ReadView.h:200
virtual std::unique_ptr< SlesType::iter_base > slesEnd() const =0
SLE::const_pointer mapped_type
Definition ReadView.h:47
virtual STAmount balanceHookIOU(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition ReadView.h:180
Rules controlling protocol behavior.
Definition Rules.h:40
constexpr bool holds() const noexcept
Definition STAmount.h:478
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:370
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:34
BaseUInt< 256 > uint256
Definition base_uint.h:580
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 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