rippled
Loading...
Searching...
No Matches
ApplyView.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_APPLYVIEW_H_INCLUDED
21#define RIPPLE_LEDGER_APPLYVIEW_H_INCLUDED
22
23#include <xrpld/ledger/RawView.h>
24#include <xrpld/ledger/ReadView.h>
25
26#include <xrpl/basics/safe_cast.h>
27#include <xrpl/beast/utility/instrumentation.h>
28
29namespace ripple {
30
32 tapNONE = 0x00,
33
34 // This is a local transaction with the
35 // fail_hard flag set.
37
38 // This is not the transaction's last pass
39 // Transaction can be retried, soft failures allowed
40 tapRETRY = 0x20,
41
42 // Transaction came from a privileged source
43 tapUNLIMITED = 0x400,
44
45 // Transaction is executing as part of a batch
46 tapBATCH = 0x800,
47
48 // Transaction shouldn't be applied
49 // Signatures shouldn't be checked
50 tapDRY_RUN = 0x1000
51};
52
53constexpr ApplyFlags
54operator|(ApplyFlags const& lhs, ApplyFlags const& rhs)
55{
56 return safe_cast<ApplyFlags>(
59}
60
61static_assert(
62 (tapFAIL_HARD | tapRETRY) == safe_cast<ApplyFlags>(0x30u),
63 "ApplyFlags operator |");
64static_assert(
65 (tapRETRY | tapFAIL_HARD) == safe_cast<ApplyFlags>(0x30u),
66 "ApplyFlags operator |");
67
68constexpr ApplyFlags
69operator&(ApplyFlags const& lhs, ApplyFlags const& rhs)
70{
71 return safe_cast<ApplyFlags>(
74}
75
76static_assert((tapFAIL_HARD & tapRETRY) == tapNONE, "ApplyFlags operator &");
77static_assert((tapRETRY & tapFAIL_HARD) == tapNONE, "ApplyFlags operator &");
78
79constexpr ApplyFlags
81{
82 return safe_cast<ApplyFlags>(
84}
85
86static_assert(
87 ~tapRETRY == safe_cast<ApplyFlags>(0xFFFFFFDFu),
88 "ApplyFlags operator ~");
89
90inline ApplyFlags
92{
93 lhs = lhs | rhs;
94 return lhs;
95}
96
97inline ApplyFlags
99{
100 lhs = lhs & rhs;
101 return lhs;
102}
103
104//------------------------------------------------------------------------------
105
143class ApplyView : public ReadView
144{
145private:
148 dirAdd(
149 bool preserveOrder,
150 Keylet const& directory,
151 uint256 const& key,
152 std::function<void(std::shared_ptr<SLE> const&)> const& describe);
153
154public:
155 ApplyView() = default;
156
165 virtual ApplyFlags
166 flags() const = 0;
167
183 peek(Keylet const& k) = 0;
184
196 virtual void
198
217 virtual void
219
236 virtual void
238
239 //--------------------------------------------------------------------------
240
241 // Called when a credit is made to an account
242 // This is required to support PaymentSandbox
243 virtual void
245 AccountID const& from,
246 AccountID const& to,
247 STAmount const& amount,
248 STAmount const& preCreditBalance)
249 {
250 }
251
252 // Called when the owner count changes
253 // This is required to support PaymentSandbox
254 virtual void
256 AccountID const& account,
257 std::uint32_t cur,
258 std::uint32_t next)
259 {
260 }
261
282 Keylet const& directory,
283 Keylet const& key,
284 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
285 {
286 if (key.type != ltOFFER)
287 {
288 UNREACHABLE(
289 "ripple::ApplyView::dirAppend : only Offers are appended to "
290 "book directories");
291 // Only Offers are appended to book directories. Call dirInsert()
292 // instead
293 return std::nullopt;
294 }
295 return dirAdd(true, directory, key.key, describe);
296 }
319 Keylet const& directory,
320 uint256 const& key,
321 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
322 {
323 return dirAdd(false, directory, key, describe);
324 }
325
328 Keylet const& directory,
329 Keylet const& key,
330 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
331 {
332 return dirAdd(false, directory, key.key, describe);
333 }
352 bool
353 dirRemove(
354 Keylet const& directory,
355 std::uint64_t page,
356 uint256 const& key,
357 bool keepRoot);
358
359 bool
361 Keylet const& directory,
362 std::uint64_t page,
363 Keylet const& key,
364 bool keepRoot)
365 {
366 return dirRemove(directory, page, key.key, keepRoot);
367 }
371 bool
372 dirDelete(
373 Keylet const& directory,
374 std::function<void(uint256 const&)> const&);
375
385 bool
386 emptyDirDelete(Keylet const& directory);
387};
388
389} // namespace ripple
390
391#endif
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:144
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:327
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
Definition: ApplyView.h:244
ApplyView()=default
bool dirDelete(Keylet const &directory, std::function< void(uint256 const &)> const &)
Remove the specified directory, invoking the callback for every node.
Definition: ApplyView.cpp:339
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.
Definition: ApplyView.cpp:190
bool emptyDirDelete(Keylet const &directory)
Remove the specified directory, if it is empty.
Definition: ApplyView.cpp:126
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:281
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
Definition: ApplyView.h:255
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:29
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:360
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:318
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:52
Match set account flags.
Definition: flags.h:125
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
ApplyFlags operator|=(ApplyFlags &lhs, ApplyFlags const &rhs)
Definition: ApplyView.h:91
OptionaledField< T > operator~(TypedField< T > const &f)
Definition: SField.h:334
constexpr base_uint< Bits, Tag > operator|(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:615
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:42
ApplyFlags operator&=(ApplyFlags &lhs, ApplyFlags const &rhs)
Definition: ApplyView.h:98
constexpr base_uint< Bits, Tag > operator&(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:608
ApplyFlags
Definition: ApplyView.h:31
@ tapFAIL_HARD
Definition: ApplyView.h:36
@ tapUNLIMITED
Definition: ApplyView.h:43
@ tapRETRY
Definition: ApplyView.h:40
@ tapDRY_RUN
Definition: ApplyView.h:50
@ tapBATCH
Definition: ApplyView.h:46
@ tapNONE
Definition: ApplyView.h:32
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
LedgerEntryType type
Definition: Keylet.h:41
uint256 key
Definition: Keylet.h:40