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
45constexpr ApplyFlags
46operator|(ApplyFlags const& lhs, ApplyFlags const& rhs)
47{
48 return safe_cast<ApplyFlags>(
51}
52
53static_assert(
54 (tapFAIL_HARD | tapRETRY) == safe_cast<ApplyFlags>(0x30u),
55 "ApplyFlags operator |");
56static_assert(
57 (tapRETRY | tapFAIL_HARD) == safe_cast<ApplyFlags>(0x30u),
58 "ApplyFlags operator |");
59
60constexpr ApplyFlags
61operator&(ApplyFlags const& lhs, ApplyFlags const& rhs)
62{
63 return safe_cast<ApplyFlags>(
66}
67
68static_assert((tapFAIL_HARD & tapRETRY) == tapNONE, "ApplyFlags operator &");
69static_assert((tapRETRY & tapFAIL_HARD) == tapNONE, "ApplyFlags operator &");
70
71constexpr ApplyFlags
72operator~(ApplyFlags const& flags)
73{
74 return safe_cast<ApplyFlags>(
76}
77
78static_assert(
79 ~tapRETRY == safe_cast<ApplyFlags>(0xFFFFFFDFu),
80 "ApplyFlags operator ~");
81
82inline ApplyFlags
84{
85 lhs = lhs | rhs;
86 return lhs;
87}
88
89inline ApplyFlags
91{
92 lhs = lhs & rhs;
93 return lhs;
94}
95
96//------------------------------------------------------------------------------
97
135class ApplyView : public ReadView
136{
137private:
140 dirAdd(
141 bool preserveOrder,
142 Keylet const& directory,
143 uint256 const& key,
144 std::function<void(std::shared_ptr<SLE> const&)> const& describe);
145
146public:
147 ApplyView() = default;
148
157 virtual ApplyFlags
158 flags() const = 0;
159
175 peek(Keylet const& k) = 0;
176
188 virtual void
190
209 virtual void
211
228 virtual void
230
231 //--------------------------------------------------------------------------
232
233 // Called when a credit is made to an account
234 // This is required to support PaymentSandbox
235 virtual void
237 AccountID const& from,
238 AccountID const& to,
239 STAmount const& amount,
240 STAmount const& preCreditBalance)
241 {
242 }
243
244 // Called when the owner count changes
245 // This is required to support PaymentSandbox
246 virtual void
248 AccountID const& account,
249 std::uint32_t cur,
250 std::uint32_t next)
251 {
252 }
253
274 Keylet const& directory,
275 Keylet const& key,
276 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
277 {
278 if (key.type != ltOFFER)
279 {
280 UNREACHABLE(
281 "ripple::ApplyView::dirAppend : only Offers are appended to "
282 "book directories");
283 // Only Offers are appended to book directories. Call dirInsert()
284 // instead
285 return std::nullopt;
286 }
287 return dirAdd(true, directory, key.key, describe);
288 }
311 Keylet const& directory,
312 uint256 const& key,
313 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
314 {
315 return dirAdd(false, directory, key, describe);
316 }
317
320 Keylet const& directory,
321 Keylet const& key,
322 std::function<void(std::shared_ptr<SLE> const&)> const& describe)
323 {
324 return dirAdd(false, directory, key.key, describe);
325 }
344 bool
345 dirRemove(
346 Keylet const& directory,
347 std::uint64_t page,
348 uint256 const& key,
349 bool keepRoot);
350
351 bool
353 Keylet const& directory,
354 std::uint64_t page,
355 Keylet const& key,
356 bool keepRoot)
357 {
358 return dirRemove(directory, page, key.key, keepRoot);
359 }
363 bool
364 dirDelete(
365 Keylet const& directory,
366 std::function<void(uint256 const&)> const&);
367
377 bool
378 emptyDirDelete(Keylet const& directory);
379};
380
381} // namespace ripple
382
383#endif
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:136
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:319
virtual void creditHook(AccountID const &from, AccountID const &to, STAmount const &amount, STAmount const &preCreditBalance)
Definition: ApplyView.h:236
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:273
virtual void adjustOwnerCountHook(AccountID const &account, std::uint32_t cur, std::uint32_t next)
Definition: ApplyView.h:247
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:352
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:310
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:83
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:90
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
@ 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