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 <xrpld/ledger/detail/ReadViewFwdRange.h>
24#include <xrpl/basics/chrono.h>
25#include <xrpl/beast/hash/uhash.h>
26#include <xrpl/beast/utility/Journal.h>
27#include <xrpl/beast/utility/instrumentation.h>
28#include <xrpl/protocol/FeeUnits.h>
29#include <xrpl/protocol/Fees.h>
30#include <xrpl/protocol/IOUAmount.h>
31#include <xrpl/protocol/Indexes.h>
32#include <xrpl/protocol/LedgerHeader.h>
33#include <xrpl/protocol/Protocol.h>
34#include <xrpl/protocol/Rules.h>
35#include <xrpl/protocol/STAmount.h>
36#include <xrpl/protocol/STLedgerEntry.h>
37#include <xrpl/protocol/STTx.h>
38#include <xrpl/protocol/XRPAmount.h>
39#include <cstdint>
40#include <memory>
41#include <optional>
42#include <unordered_set>
43
44namespace ripple {
45
46//------------------------------------------------------------------------------
47
55{
56public:
57 using tx_type =
59
61
63
64 struct sles_type : detail::ReadViewFwdRange<std::shared_ptr<SLE const>>
65 {
66 explicit sles_type(ReadView const& view);
68 begin() const;
70 end() const;
72 upper_bound(key_type const& key) const;
73 };
74
76 {
77 explicit txs_type(ReadView const& view);
78 bool
79 empty() const;
80 iterator
81 begin() const;
82 iterator
83 end() const;
84 };
85
86 virtual ~ReadView() = default;
87
89 operator=(ReadView&& other) = delete;
91 operator=(ReadView const& other) = delete;
92
93 ReadView() : sles(*this), txs(*this)
94 {
95 }
96
97 ReadView(ReadView const& other) : sles(*this), txs(*this)
98 {
99 }
100
101 ReadView(ReadView&& other) : sles(*this), txs(*this)
102 {
103 }
104
106 virtual LedgerInfo const&
107 info() const = 0;
108
110 virtual bool
111 open() const = 0;
112
116 {
117 return info().parentCloseTime;
118 }
119
122 seq() const
123 {
124 return info().seq;
125 }
126
128 virtual Fees const&
129 fees() const = 0;
130
132 virtual Rules const&
133 rules() const = 0;
134
142 virtual bool
143 exists(Keylet const& k) const = 0;
144
157 key_type const& key,
158 std::optional<key_type> const& last = std::nullopt) const = 0;
159
174 read(Keylet const& k) const = 0;
175
176 // Accounts in a payment are not allowed to use assets acquired during that
177 // payment. The PaymentSandbox tracks the debits, credits, and owner count
178 // changes that accounts make during a payment. `balanceHook` adjusts
179 // balances so newly acquired assets are not counted toward the balance.
180 // This is required to support PaymentSandbox.
181 virtual STAmount
183 AccountID const& account,
184 AccountID const& issuer,
185 STAmount const& amount) const
186 {
187 return amount;
188 }
189
190 // Accounts in a payment are not allowed to use assets acquired during that
191 // payment. The PaymentSandbox tracks the debits, credits, and owner count
192 // changes that accounts make during a payment. `ownerCountHook` adjusts the
193 // ownerCount so it returns the max value of the ownerCount so far.
194 // This is required to support PaymentSandbox.
195 virtual std::uint32_t
196 ownerCountHook(AccountID const& account, std::uint32_t count) const
197 {
198 return count;
199 }
200
201 // used by the implementation
203 slesBegin() const = 0;
204
205 // used by the implementation
207 slesEnd() const = 0;
208
209 // used by the implementation
211 slesUpperBound(key_type const& key) const = 0;
212
213 // used by the implementation
215 txsBegin() const = 0;
216
217 // used by the implementation
219 txsEnd() const = 0;
220
226 virtual bool
227 txExists(key_type const& key) const = 0;
228
237 virtual tx_type
238 txRead(key_type const& key) const = 0;
239
240 //
241 // Memberspaces
242 //
243
250
251 // The range of transactions
253};
254
255//------------------------------------------------------------------------------
256
259{
260public:
262
265
271 digest(key_type const& key) const = 0;
272};
273
274//------------------------------------------------------------------------------
275
276Rules
278
279Rules
281 DigestAwareReadView const& ledger,
282 std::unordered_set<uint256, beast::uhash<>> const& presets);
283
284} // namespace ripple
285
286#include <xrpld/ledger/detail/ReadViewFwdRange.ipp>
287
288#endif
ReadView that associates keys with digests.
Definition: ReadView.h:259
DigestAwareReadView(const DigestAwareReadView &)=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:55
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:101
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
Definition: ReadView.h:115
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
txs_type txs
Definition: ReadView.h:252
virtual std::uint32_t ownerCountHook(AccountID const &account, std::uint32_t count) const
Definition: ReadView.h:196
virtual STAmount balanceHook(AccountID const &account, AccountID const &issuer, STAmount const &amount) const
Definition: ReadView.h:182
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:122
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:97
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:249
Rules controlling protocol behavior.
Definition: Rules.h:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 256 > uint256
Definition: base_uint.h:557
@ 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.
Definition: protocol/Fees.h:33
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
Information about the notional ledger backing the view.
Definition: LedgerHeader.h:34
NetClock::time_point parentCloseTime
Definition: LedgerHeader.h:42
iterator upper_bound(key_type const &key) const
Definition: ReadView.cpp:41
iterator end() const
Definition: ReadView.cpp:35
iterator begin() const
Definition: ReadView.cpp:29
iterator end() const
Definition: ReadView.cpp:63
iterator begin() const
Definition: ReadView.cpp:57