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 shouldn't be applied
46 // Signatures shouldn't be checked
47 tapDRY_RUN = 0x1000
48};
49
50constexpr ApplyFlags
51operator|(ApplyFlags const& lhs, ApplyFlags const& rhs)
52{
53 return safe_cast<ApplyFlags>(
56}
57
58static_assert(
59 (tapFAIL_HARD | tapRETRY) == safe_cast<ApplyFlags>(0x30u),
60 "ApplyFlags operator |");
61static_assert(
62 (tapRETRY | tapFAIL_HARD) == safe_cast<ApplyFlags>(0x30u),
63 "ApplyFlags operator |");
64
65constexpr ApplyFlags
66operator&(ApplyFlags const& lhs, ApplyFlags const& rhs)
67{
68 return safe_cast<ApplyFlags>(
71}
72
73static_assert((tapFAIL_HARD & tapRETRY) == tapNONE, "ApplyFlags operator &");
74static_assert((tapRETRY & tapFAIL_HARD) == tapNONE, "ApplyFlags operator &");
75
76constexpr ApplyFlags
78{
79 return safe_cast<ApplyFlags>(
81}
82
83static_assert(
84 ~tapRETRY == safe_cast<ApplyFlags>(0xFFFFFFDFu),
85 "ApplyFlags operator ~");
86
87inline ApplyFlags
89{
90 lhs = lhs | rhs;
91 return lhs;
92}
93
94inline ApplyFlags
96{
97 lhs = lhs & rhs;
98 return lhs;
99}
100
101//------------------------------------------------------------------------------
102
140class ApplyView : public ReadView
141{
142private:
145 dirAdd(
146 bool preserveOrder,
147 Keylet const& directory,
148 uint256 const& key,
149 std::function<void(std::shared_ptr<SLE> const&)> const& describe);
150
151public:
152 ApplyView() = default;
153
162 virtual ApplyFlags
163 flags() const = 0;
164
180 peek(Keylet const& k) = 0;
181
193 virtual void
195
214 virtual void
216
233 virtual void
235
236 //--------------------------------------------------------------------------
237
238 // Called when a credit is made to an account
239 // This is required to support PaymentSandbox
240 virtual void
242 AccountID const& from,
243 AccountID const& to,
244 STAmount const& amount,
245 STAmount const& preCreditBalance)
246 {
247 }
248
249 // Called when the owner count changes
250 // This is required to support PaymentSandbox
251 virtual void
253 AccountID const& account,
254 std::uint32_t cur,
255 std::uint32_t next)
256 {
257 }
258
279 Keylet const& directory,
280 Keylet const& key,
281 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
282 {
283 if (key.type != ltOFFER)
284 {
285 UNREACHABLE(
286 "ripple::ApplyView::dirAppend : only Offers are appended to "
287 "book directories");
288 // Only Offers are appended to book directories. Call dirInsert()
289 // instead
290 return std::nullopt;
291 }
292 return dirAdd(true, directory, key.key, describe);
293 }
316 Keylet const& directory,
317 uint256 const& key,
318 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
319 {
320 return dirAdd(false, directory, key, describe);
321 }
322
325 Keylet const& directory,
326 Keylet const& key,
327 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
328 {
329 return dirAdd(false, directory, key.key, describe);
330 }
349 bool
350 dirRemove(
351 Keylet const& directory,
352 std::uint64_t page,
353 uint256 const& key,
354 bool keepRoot);
355
356 bool
358 Keylet const& directory,
359 std::uint64_t page,
360 Keylet const& key,
361 bool keepRoot)
362 {
363 return dirRemove(directory, page, key.key, keepRoot);
364 }
368 bool
369 dirDelete(
370 Keylet const& directory,
371 std::function<void(uint256 const&)> const&);
372
382 bool
383 emptyDirDelete(Keylet const& directory);
384};
385
386} // namespace ripple
387
388#endif
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:141
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:324
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
Definition: ApplyView.h:241
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:278
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
Definition: ApplyView.h:252
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:357
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:315
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:88
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:95
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:47
@ 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