rippled
Loading...
Searching...
No Matches
ApplyView.h
1#pragma once
2
3#include <xrpl/basics/safe_cast.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/ledger/RawView.h>
6#include <xrpl/ledger/ReadView.h>
7
8namespace xrpl {
9
11 tapNONE = 0x00,
12
13 // This is a local transaction with the
14 // fail_hard flag set.
16
17 // This is not the transaction's last pass
18 // Transaction can be retried, soft failures allowed
19 tapRETRY = 0x20,
20
21 // Transaction came from a privileged source
22 tapUNLIMITED = 0x400,
23
24 // Transaction is executing as part of a batch
25 tapBATCH = 0x800,
26
27 // Transaction shouldn't be applied
28 // Signatures shouldn't be checked
29 tapDRY_RUN = 0x1000
30};
31
32constexpr ApplyFlags
33operator|(ApplyFlags const& lhs, ApplyFlags const& rhs)
34{
35 return safe_cast<ApplyFlags>(
38}
39
40static_assert((tapFAIL_HARD | tapRETRY) == safe_cast<ApplyFlags>(0x30u), "ApplyFlags operator |");
41static_assert((tapRETRY | tapFAIL_HARD) == safe_cast<ApplyFlags>(0x30u), "ApplyFlags operator |");
42
43constexpr ApplyFlags
44operator&(ApplyFlags const& lhs, ApplyFlags const& rhs)
45{
46 return safe_cast<ApplyFlags>(
49}
50
51static_assert((tapFAIL_HARD & tapRETRY) == tapNONE, "ApplyFlags operator &");
52static_assert((tapRETRY & tapFAIL_HARD) == tapNONE, "ApplyFlags operator &");
53
54constexpr ApplyFlags
55operator~(ApplyFlags const& flags)
56{
57 return safe_cast<ApplyFlags>(~safe_cast<std::underlying_type_t<ApplyFlags>>(flags));
58}
59
60static_assert(~tapRETRY == safe_cast<ApplyFlags>(0xFFFFFFDFu), "ApplyFlags operator ~");
61
62inline ApplyFlags
64{
65 lhs = lhs | rhs;
66 return lhs;
67}
68
69inline ApplyFlags
71{
72 lhs = lhs & rhs;
73 return lhs;
74}
75
76//------------------------------------------------------------------------------
77
115class ApplyView : public ReadView
116{
117private:
120 dirAdd(
121 bool preserveOrder,
122 Keylet const& directory,
123 uint256 const& key,
124 std::function<void(std::shared_ptr<SLE> const&)> const& describe);
125
126public:
127 ApplyView() = default;
128
137 virtual ApplyFlags
138 flags() const = 0;
139
155 peek(Keylet const& k) = 0;
156
168 virtual void
170
189 virtual void
191
208 virtual void
210
211 //--------------------------------------------------------------------------
212
213 // Called when a credit is made to an account
214 // This is required to support PaymentSandbox
215 virtual void
217 AccountID const& from,
218 AccountID const& to,
219 STAmount const& amount,
220 STAmount const& preCreditBalance)
221 {
222 }
223
224 // Called when the owner count changes
225 // This is required to support PaymentSandbox
226 virtual void
228 {
229 }
230
251 Keylet const& directory,
252 Keylet const& key,
253 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
254 {
255 if (key.type != ltOFFER)
256 {
257 // LCOV_EXCL_START
258 UNREACHABLE(
259 "xrpl::ApplyView::dirAppend : only Offers are appended to "
260 "book directories");
261 // Only Offers are appended to book directories. Call dirInsert()
262 // instead
263 return std::nullopt;
264 // LCOV_EXCL_STOP
265 }
266 return dirAdd(true, directory, key.key, describe);
267 }
290 Keylet const& directory,
291 uint256 const& key,
292 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
293 {
294 return dirAdd(false, directory, key, describe);
295 }
296
299 Keylet const& directory,
300 Keylet const& key,
301 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
302 {
303 return dirAdd(false, directory, key.key, describe);
304 }
323 bool
324 dirRemove(Keylet const& directory, std::uint64_t page, uint256 const& key, bool keepRoot);
325
326 bool
327 dirRemove(Keylet const& directory, std::uint64_t page, Keylet const& key, bool keepRoot)
328 {
329 return dirRemove(directory, page, key.key, keepRoot);
330 }
334 bool
335 dirDelete(Keylet const& directory, std::function<void(uint256 const&)> const&);
336
346 bool
347 emptyDirDelete(Keylet const& directory);
348};
349
350namespace directory {
360 ApplyView& view,
361 Keylet const& directory,
362 uint256 const& key,
363 std::function<void(std::shared_ptr<SLE> const&)> const& describe);
364
365auto
366findPreviousPage(ApplyView& view, Keylet const& directory, SLE::ref start);
367
370 ApplyView& view,
371 SLE::ref node,
372 std::uint64_t page,
373 bool preserveOrder,
374 STVector256& indexes,
375 uint256 const& key);
376
379 ApplyView& view,
380 std::uint64_t page,
381 SLE::pointer node,
382 std::uint64_t nextPage,
383 SLE::ref next,
384 uint256 const& key,
385 Keylet const& directory,
386 std::function<void(std::shared_ptr<SLE> const&)> const& describe);
387
388} // namespace directory
389} // namespace xrpl
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:116
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.
ApplyView()=default
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, Keylet const &key, bool keepRoot)
Definition ApplyView.h:327
bool dirDelete(Keylet const &directory, std::function< void(uint256 const &)> const &)
Remove the specified directory, invoking the callback for every node.
virtual ApplyFlags flags() const =0
Returns the tx apply flags.
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:298
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
bool emptyDirDelete(Keylet const &directory)
Remove the specified directory, if it is empty.
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
Definition ApplyView.h:216
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
Definition ApplyView.h:227
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.
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:289
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
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:250
A view into a ledger.
Definition ReadView.h:31
T is_same_v
auto findPreviousPage(ApplyView &view, Keylet const &directory, SLE::ref start)
Definition ApplyView.cpp:33
std::uint64_t insertKey(ApplyView &view, SLE::ref node, std::uint64_t page, bool preserveOrder, STVector256 &indexes, uint256 const &key)
Definition ApplyView.cpp:54
std::optional< std::uint64_t > insertPage(ApplyView &view, std::uint64_t page, SLE::pointer node, std::uint64_t nextPage, SLE::ref next, uint256 const &key, Keylet const &directory, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Definition ApplyView.cpp:90
std::uint64_t createRoot(ApplyView &view, Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Helper functions for managing low-level directory operations.
Definition ApplyView.cpp:14
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr ApplyFlags operator~(ApplyFlags const &flags)
Definition ApplyView.h:55
constexpr HashRouterFlags & operator|=(HashRouterFlags &lhs, HashRouterFlags rhs)
Definition HashRouter.h:41
constexpr base_uint< Bits, Tag > operator|(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition base_uint.h:587
constexpr HashRouterFlags & operator&=(HashRouterFlags &lhs, HashRouterFlags rhs)
Definition HashRouter.h:56
constexpr base_uint< Bits, Tag > operator&(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition base_uint.h:580
ApplyFlags
Definition ApplyView.h:10
@ tapDRY_RUN
Definition ApplyView.h:29
@ tapNONE
Definition ApplyView.h:11
@ tapRETRY
Definition ApplyView.h:19
@ tapFAIL_HARD
Definition ApplyView.h:15
@ tapUNLIMITED
Definition ApplyView.h:22
@ tapBATCH
Definition ApplyView.h:25
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:21
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
uint256 key
Definition Keylet.h:20
LedgerEntryType type
Definition Keylet.h:21