xrpld
Loading...
Searching...
No Matches
ApplyContext.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/core/ServiceRegistry.h>
5#include <xrpl/ledger/ApplyViewImpl.h>
6#include <xrpl/protocol/STTx.h>
7#include <xrpl/protocol/XRPAmount.h>
8
9#include <optional>
10
11namespace xrpl {
12
15{
16public:
17 explicit ApplyContext(
19 OpenView& base,
20 std::optional<uint256 const> const& parentBatchId,
21 STTx const& tx,
26
27 explicit ApplyContext(
29 OpenView& base,
30 STTx const& tx,
36 {
37 XRPL_ASSERT((flags & TapBatch) == 0, "Batch apply flag should not be set");
38 }
39
41 STTx const& tx;
45
48 {
49 return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor
50 }
51
52 [[nodiscard]] ApplyView const&
53 view() const
54 {
55 return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor
56 }
57
58 // VFALCO Unfortunately this is necessary
59 RawView&
61 {
62 return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor
63 }
64
65 [[nodiscard]] ApplyFlags const&
66 flags() const
67 {
68 return flags_;
69 }
70
72 void
73 deliver(STAmount const& amount)
74 {
75 // NOLINTNEXTLINE(bugprone-unchecked-optional-access) view_ emplaced in constructor
76 view_->deliver(amount);
77 }
78
80 void
81 discard();
82
85
88 size();
89
91 void
92 visit(
93 std::function<void(
94 uint256 const& key,
95 bool isDelete,
96 SLE::const_ref before,
97 SLE::const_ref after)> const& func);
98
99 void
101 {
102 // NOLINTNEXTLINE(bugprone-unchecked-optional-access) view_ emplaced in constructor
103 view_->rawDestroyXRP(fee);
104 }
105
112 TER
113 checkInvariants(TER const result, XRPAmount const fee);
114
115private:
116 static TER
117 failInvariantCheck(TER const result);
118
119 template <std::size_t... Is>
120 TER
122
126
127 // The ID of the batch transaction we are executing under, if seated.
129};
130
131} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
static Sink & getNullSink()
Returns a Sink which does nothing.
State information when applying a tx.
std::size_t size()
Get the number of unapplied changes.
STTx const & tx
static TER failInvariantCheck(TER const result)
void destroyXRP(XRPAmount const &fee)
XRPAmount const baseFee
ApplyFlags const & flags() const
void discard()
Discard changes and start fresh.
std::reference_wrapper< ServiceRegistry > registry
void deliver(STAmount const &amount)
Sets the DeliveredAmount field in the metadata.
std::optional< TxMeta > apply(TER)
Apply the transaction result to the base.
std::optional< ApplyViewImpl > view_
beast::Journal const journal
ApplyView const & view() const
RawView & rawView()
TER checkInvariantsHelper(TER const result, XRPAmount const fee, std::index_sequence< Is... >)
ApplyView & view()
void visit(std::function< void(uint256 const &key, bool isDelete, SLE::const_ref before, SLE::const_ref after)> const &func)
Visit unapplied changes.
TER checkInvariants(TER const result, XRPAmount const fee)
Applies all invariant checkers one by one.
std::optional< uint256 const > parentBatchId_
ApplyContext(ServiceRegistry &registry, OpenView &base, STTx const &tx, TER preclaimResult, XRPAmount baseFee, ApplyFlags flags, beast::Journal journal=beast::Journal{beast::Journal::getNullSink()})
TER const preclaimResult
ApplyContext(ServiceRegistry &registry, OpenView &base, std::optional< uint256 const > const &parentBatchId, STTx const &tx, TER preclaimResult, XRPAmount baseFee, ApplyFlags flags, beast::Journal journal=beast::Journal{beast::Journal::getNullSink()})
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:118
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:45
Interface for ledger entry changes.
Definition RawView.h:14
std::shared_ptr< STLedgerEntry const > const & const_ref
Service registry for dependency injection.
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:554
ApplyFlags
Definition ApplyView.h:12
@ TapBatch
Definition ApplyView.h:27
TERSubset< CanCvtToTER > TER
Definition TER.h:634
BaseUInt< 256 > uint256
Definition base_uint.h:562