rippled
Loading...
Searching...
No Matches
ApplyView.h
1#ifndef XRPL_LEDGER_APPLYVIEW_H_INCLUDED
2#define XRPL_LEDGER_APPLYVIEW_H_INCLUDED
3
4#include <xrpl/basics/safe_cast.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/ledger/RawView.h>
7#include <xrpl/ledger/ReadView.h>
8
9namespace ripple {
10
12 tapNONE = 0x00,
13
14 // This is a local transaction with the
15 // fail_hard flag set.
17
18 // This is not the transaction's last pass
19 // Transaction can be retried, soft failures allowed
20 tapRETRY = 0x20,
21
22 // Transaction came from a privileged source
23 tapUNLIMITED = 0x400,
24
25 // Transaction is executing as part of a batch
26 tapBATCH = 0x800,
27
28 // Transaction shouldn't be applied
29 // Signatures shouldn't be checked
30 tapDRY_RUN = 0x1000
31};
32
33constexpr ApplyFlags
34operator|(ApplyFlags const& lhs, ApplyFlags const& rhs)
35{
36 return safe_cast<ApplyFlags>(
39}
40
41static_assert(
42 (tapFAIL_HARD | tapRETRY) == safe_cast<ApplyFlags>(0x30u),
43 "ApplyFlags operator |");
44static_assert(
45 (tapRETRY | tapFAIL_HARD) == safe_cast<ApplyFlags>(0x30u),
46 "ApplyFlags operator |");
47
48constexpr ApplyFlags
49operator&(ApplyFlags const& lhs, ApplyFlags const& rhs)
50{
51 return safe_cast<ApplyFlags>(
54}
55
56static_assert((tapFAIL_HARD & tapRETRY) == tapNONE, "ApplyFlags operator &");
57static_assert((tapRETRY & tapFAIL_HARD) == tapNONE, "ApplyFlags operator &");
58
59constexpr ApplyFlags
60operator~(ApplyFlags const& flags)
61{
62 return safe_cast<ApplyFlags>(
64}
65
66static_assert(
67 ~tapRETRY == safe_cast<ApplyFlags>(0xFFFFFFDFu),
68 "ApplyFlags operator ~");
69
70inline ApplyFlags
72{
73 lhs = lhs | rhs;
74 return lhs;
75}
76
77inline ApplyFlags
79{
80 lhs = lhs & rhs;
81 return lhs;
82}
83
84//------------------------------------------------------------------------------
85
123class ApplyView : public ReadView
124{
125private:
128 dirAdd(
129 bool preserveOrder,
130 Keylet const& directory,
131 uint256 const& key,
132 std::function<void(std::shared_ptr<SLE> const&)> const& describe);
133
134public:
135 ApplyView() = default;
136
145 virtual ApplyFlags
146 flags() const = 0;
147
163 peek(Keylet const& k) = 0;
164
176 virtual void
178
197 virtual void
199
216 virtual void
218
219 //--------------------------------------------------------------------------
220
221 // Called when a credit is made to an account
222 // This is required to support PaymentSandbox
223 virtual void
225 AccountID const& from,
226 AccountID const& to,
227 STAmount const& amount,
228 STAmount const& preCreditBalance)
229 {
230 }
231
232 // Called when the owner count changes
233 // This is required to support PaymentSandbox
234 virtual void
236 AccountID const& account,
237 std::uint32_t cur,
238 std::uint32_t next)
239 {
240 }
241
262 Keylet const& directory,
263 Keylet const& key,
264 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
265 {
266 if (key.type != ltOFFER)
267 {
268 // LCOV_EXCL_START
269 UNREACHABLE(
270 "ripple::ApplyView::dirAppend : only Offers are appended to "
271 "book directories");
272 // Only Offers are appended to book directories. Call dirInsert()
273 // instead
274 return std::nullopt;
275 // LCOV_EXCL_STOP
276 }
277 return dirAdd(true, directory, key.key, describe);
278 }
301 Keylet const& directory,
302 uint256 const& key,
303 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
304 {
305 return dirAdd(false, directory, key, describe);
306 }
307
310 Keylet const& directory,
311 Keylet const& key,
312 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
313 {
314 return dirAdd(false, directory, key.key, describe);
315 }
334 bool
335 dirRemove(
336 Keylet const& directory,
337 std::uint64_t page,
338 uint256 const& key,
339 bool keepRoot);
340
341 bool
343 Keylet const& directory,
344 std::uint64_t page,
345 Keylet const& key,
346 bool keepRoot)
347 {
348 return dirRemove(directory, page, key.key, keepRoot);
349 }
353 bool
354 dirDelete(
355 Keylet const& directory,
356 std::function<void(uint256 const&)> const&);
357
367 bool
368 emptyDirDelete(Keylet const& directory);
369};
370
371} // namespace ripple
372
373#endif
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:124
std::optional< std::uint64_t > dirInsert(Keylet const &directory, Keylet const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Definition ApplyView.h:309
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
Definition ApplyView.h:224
ApplyView()=default
bool dirDelete(Keylet const &directory, std::function< void(uint256 const &)> const &)
Remove the specified directory, invoking the callback for every node.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
bool emptyDirDelete(Keylet const &directory)
Remove the specified directory, if it is empty.
std::optional< std::uint64_t > dirAppend(Keylet const &directory, Keylet const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Append an entry to a directory.
Definition ApplyView.h:261
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
Definition ApplyView.h:235
std::optional< std::uint64_t > dirAdd(bool preserveOrder, Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Add an entry to a directory using the specified insert strategy.
Definition ApplyView.cpp:12
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
virtual ApplyFlags flags() const =0
Returns the tx apply flags.
bool dirRemove(Keylet const &directory, std::uint64_t page, Keylet const &key, bool keepRoot)
Definition ApplyView.h:342
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
Definition ApplyView.h:300
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
A view into a ledger.
Definition ReadView.h:32
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
ApplyFlags operator|=(ApplyFlags &lhs, ApplyFlags const &rhs)
Definition ApplyView.h:71
constexpr base_uint< Bits, Tag > operator|(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition base_uint.h:596
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > safe_cast(Src s) noexcept
Definition safe_cast.h:22
ApplyFlags operator&=(ApplyFlags &lhs, ApplyFlags const &rhs)
Definition ApplyView.h:78
constexpr ApplyFlags operator~(ApplyFlags const &flags)
Definition ApplyView.h:60
constexpr base_uint< Bits, Tag > operator&(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition base_uint.h:589
@ tapFAIL_HARD
Definition ApplyView.h:16
@ tapUNLIMITED
Definition ApplyView.h:23
@ tapRETRY
Definition ApplyView.h:20
@ tapDRY_RUN
Definition ApplyView.h:30
@ tapBATCH
Definition ApplyView.h:26
@ tapNONE
Definition ApplyView.h:12
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
LedgerEntryType type
Definition Keylet.h:22
uint256 key
Definition Keylet.h:21