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 <xrpl/basics/chrono.h>
24#include <xrpl/beast/hash/uhash.h>
25#include <xrpl/ledger/detail/ReadViewFwdRange.h>
26#include <xrpl/protocol/Fees.h>
27#include <xrpl/protocol/IOUAmount.h>
28#include <xrpl/protocol/Indexes.h>
29#include <xrpl/protocol/LedgerHeader.h>
30#include <xrpl/protocol/Protocol.h>
31#include <xrpl/protocol/Rules.h>
32#include <xrpl/protocol/STAmount.h>
33#include <xrpl/protocol/STLedgerEntry.h>
34#include <xrpl/protocol/STTx.h>
35
36#include <cstdint>
37#include <optional>
38#include <unordered_set>
39
40namespace ripple {
41
42//------------------------------------------------------------------------------
43
51{
52public:
53 using tx_type =
55
57
59
60 struct sles_type : detail::ReadViewFwdRange<std::shared_ptr<SLE const>>
61 {
62 explicit sles_type(ReadView const& view);
64 begin() const;
66 end() const;
68 upper_bound(key_type const& key) const;
69 };
70
72 {
73 explicit txs_type(ReadView const& view);
74 bool
75 empty() const;
76 iterator
77 begin() const;
78 iterator
79 end() const;
80 };
81
82 virtual ~ReadView() = default;
83
85 operator=(ReadView&& other) = delete;
87 operator=(ReadView const& other) = delete;
88
89 ReadView() : sles(*this), txs(*this)
90 {
91 }
92
93 ReadView(ReadView const& other) : sles(*this), txs(*this)
94 {
95 }
96
97 ReadView(ReadView&& other) : sles(*this), txs(*this)
98 {
99 }
100
102 virtual LedgerInfo const&
103 info() const = 0;
104
106 virtual bool
107 open() const = 0;
108
112 {
113 return info().parentCloseTime;
114 }
115
118 seq() const
119 {
120 return info().seq;
121 }
122
124 virtual Fees const&
125 fees() const = 0;
126
128 virtual Rules const&
129 rules() const = 0;
130
138 virtual bool
139 exists(Keylet const& k) const = 0;
140
153 key_type const& key,
154 std::optional<key_type> const& last = std::nullopt) const = 0;
155
170 read(Keylet const& k) const = 0;
171
172 // Accounts in a payment are not allowed to use assets acquired during that
173 // payment. The PaymentSandbox tracks the debits, credits, and owner count
174 // changes that accounts make during a payment. `balanceHook` adjusts
175 // balances so newly acquired assets are not counted toward the balance.
176 // This is required to support PaymentSandbox.
177 virtual STAmount
179 AccountID const& account,
180 AccountID const& issuer,
181 STAmount const& amount) const
182 {
183 return amount;
184 }
185
186 // Accounts in a payment are not allowed to use assets acquired during that
187 // payment. The PaymentSandbox tracks the debits, credits, and owner count
188 // changes that accounts make during a payment. `ownerCountHook` adjusts the
189 // ownerCount so it returns the max value of the ownerCount so far.
190 // This is required to support PaymentSandbox.
191 virtual std::uint32_t
192 ownerCountHook(AccountID const& account, std::uint32_t count) const
193 {
194 return count;
195 }
196
197 // used by the implementation
199 slesBegin() const = 0;
200
201 // used by the implementation
203 slesEnd() const = 0;
204
205 // used by the implementation
207 slesUpperBound(key_type const& key) const = 0;
208
209 // used by the implementation
211 txsBegin() const = 0;
212
213 // used by the implementation
215 txsEnd() const = 0;
216
222 virtual bool
223 txExists(key_type const& key) const = 0;
224
233 virtual tx_type
234 txRead(key_type const& key) const = 0;
235
236 //
237 // Memberspaces
238 //
239
246
247 // The range of transactions
249};
250
251//------------------------------------------------------------------------------
252
255{
256public:
258
261
267 digest(key_type const& key) const = 0;
268};
269
270//------------------------------------------------------------------------------
271
272Rules
274
275Rules
277 DigestAwareReadView const& ledger,
278 std::unordered_set<uint256, beast::uhash<>> const& presets);
279
280} // namespace ripple
281
282#include <xrpl/ledger/detail/ReadViewFwdRange.ipp>
283
284#endif
ReadView that associates keys with digests.
Definition ReadView.h:255
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:51
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:97
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
Definition ReadView.h:111
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:192
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition ReadView.h:178
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:118
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:93
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:245
Rules controlling protocol behavior.
Definition Rules.h:38
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
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.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:39
Information about the notional ledger backing the view.
NetClock::time_point parentCloseTime
iterator upper_bound(key_type const &key) const
Definition ReadView.cpp:41
iterator begin() const
Definition ReadView.cpp:29
iterator end() const
Definition ReadView.cpp:63
iterator begin() const
Definition ReadView.cpp:57