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#include <xrpl/basics/safe_cast.h>
26#include <xrpl/beast/utility/instrumentation.h>
27
28namespace ripple {
29
31 tapNONE = 0x00,
32
33 // This is a local transaction with the
34 // fail_hard flag set.
36
37 // This is not the transaction's last pass
38 // Transaction can be retried, soft failures allowed
39 tapRETRY = 0x20,
40
41 // Transaction came from a privileged source
42 tapUNLIMITED = 0x400,
43
44 // Transaction shouldn't be applied
45 // Signatures shouldn't be checked
46 tapDRY_RUN = 0x1000
47};
48
49constexpr ApplyFlags
50operator|(ApplyFlags const& lhs, ApplyFlags const& rhs)
51{
52 return safe_cast<ApplyFlags>(
55}
56
57static_assert(
58 (tapFAIL_HARD | tapRETRY) == safe_cast<ApplyFlags>(0x30u),
59 "ApplyFlags operator |");
60static_assert(
61 (tapRETRY | tapFAIL_HARD) == safe_cast<ApplyFlags>(0x30u),
62 "ApplyFlags operator |");
63
64constexpr ApplyFlags
65operator&(ApplyFlags const& lhs, ApplyFlags const& rhs)
66{
67 return safe_cast<ApplyFlags>(
70}
71
72static_assert((tapFAIL_HARD & tapRETRY) == tapNONE, "ApplyFlags operator &");
73static_assert((tapRETRY & tapFAIL_HARD) == tapNONE, "ApplyFlags operator &");
74
75constexpr ApplyFlags
76operator~(ApplyFlags const& flags)
77{
78 return safe_cast<ApplyFlags>(
80}
81
82static_assert(
83 ~tapRETRY == safe_cast<ApplyFlags>(0xFFFFFFDFu),
84 "ApplyFlags operator ~");
85
86inline ApplyFlags
88{
89 lhs = lhs | rhs;
90 return lhs;
91}
92
93inline ApplyFlags
95{
96 lhs = lhs & rhs;
97 return lhs;
98}
99
100//------------------------------------------------------------------------------
101
139class ApplyView : public ReadView
140{
141private:
144 dirAdd(
145 bool preserveOrder,
146 Keylet const& directory,
147 uint256 const& key,
148 std::function<void(std::shared_ptr<SLE> const&)> const& describe);
149
150public:
151 ApplyView() = default;
152
161 virtual ApplyFlags
162 flags() const = 0;
163
179 peek(Keylet const& k) = 0;
180
192 virtual void
194
213 virtual void
215
232 virtual void
234
235 //--------------------------------------------------------------------------
236
237 // Called when a credit is made to an account
238 // This is required to support PaymentSandbox
239 virtual void
241 AccountID const& from,
242 AccountID const& to,
243 STAmount const& amount,
244 STAmount const& preCreditBalance)
245 {
246 }
247
248 // Called when the owner count changes
249 // This is required to support PaymentSandbox
250 virtual void
252 AccountID const& account,
253 std::uint32_t cur,
254 std::uint32_t next)
255 {
256 }
257
278 Keylet const& directory,
279 Keylet const& key,
280 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
281 {
282 if (key.type != ltOFFER)
283 {
284 UNREACHABLE(
285 "ripple::ApplyView::dirAppend : only Offers are appended to "
286 "book directories");
287 // Only Offers are appended to book directories. Call dirInsert()
288 // instead
289 return std::nullopt;
290 }
291 return dirAdd(true, directory, key.key, describe);
292 }
315 Keylet const& directory,
316 uint256 const& key,
317 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
318 {
319 return dirAdd(false, directory, key, describe);
320 }
321
324 Keylet const& directory,
325 Keylet const& key,
326 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
327 {
328 return dirAdd(false, directory, key.key, describe);
329 }
348 bool
349 dirRemove(
350 Keylet const& directory,
351 std::uint64_t page,
352 uint256 const& key,
353 bool keepRoot);
354
355 bool
357 Keylet const& directory,
358 std::uint64_t page,
359 Keylet const& key,
360 bool keepRoot)
361 {
362 return dirRemove(directory, page, key.key, keepRoot);
363 }
367 bool
368 dirDelete(
369 Keylet const& directory,
370 std::function<void(uint256 const&)> const&);
371
381 bool
382 emptyDirDelete(Keylet const& directory);
383};
384
385} // namespace ripple
386
387#endif
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:140
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:323
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
Definition: ApplyView.h:240
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:338
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:189
bool emptyDirDelete(Keylet const &directory)
Remove the specified directory, if it is empty.
Definition: ApplyView.cpp:125
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:277
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
Definition: ApplyView.h:251
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:28
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:356
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:314
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:55
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:87
OptionaledField< T > operator~(TypedField< T > const &f)
Definition: SField.h:335
constexpr base_uint< Bits, Tag > operator|(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:614
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:94
constexpr base_uint< Bits, Tag > operator&(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:607
ApplyFlags
Definition: ApplyView.h:30
@ tapFAIL_HARD
Definition: ApplyView.h:35
@ tapUNLIMITED
Definition: ApplyView.h:42
@ tapRETRY
Definition: ApplyView.h:39
@ tapDRY_RUN
Definition: ApplyView.h:46
@ tapNONE
Definition: ApplyView.h:31
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
LedgerEntryType type
Definition: Keylet.h:41
uint256 key
Definition: Keylet.h:40