xrpld
Loading...
Searching...
No Matches
ApplyContext.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/ApplyViewImpl.h>
9#include <xrpl/ledger/OpenView.h>
10#include <xrpl/ledger/RawView.h>
11#include <xrpl/protocol/STAmount.h>
12#include <xrpl/protocol/STTx.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/TxMeta.h>
15#include <xrpl/protocol/XRPAmount.h>
16
17#include <cstddef>
18#include <functional>
19#include <optional>
20#include <utility>
21
22namespace xrpl {
23
28{
29public:
30 explicit ApplyContext(
32 OpenView& base,
33 std::optional<uint256 const> const& parentBatchId,
34 STTx const& tx,
39
40 // Convenience constructor used only by tests that build an ApplyContext
41 // directly (e.g. invariant checks). Production always uses the parentBatchId
42 // constructor above; this one fixes parentBatchId to std::nullopt and so is
43 // never valid for a batch inner (hence the TapBatch assert).
44 explicit ApplyContext(
46 OpenView& base,
47 STTx const& tx,
53 {
54 XRPL_ASSERT((flags & TapBatch) == 0, "Batch apply flag should not be set");
55 }
56
58 STTx const& tx;
62
65 {
66 return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor
67 }
68
69 [[nodiscard]] ApplyView const&
70 view() const
71 {
72 return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor
73 }
74
75 // VFALCO Unfortunately this is necessary
76 RawView&
78 {
79 return *view_; // NOLINT(bugprone-unchecked-optional-access) view_ emplaced in constructor
80 }
81
82 [[nodiscard]] ApplyFlags const&
83 flags() const
84 {
85 return flags_;
86 }
87
91 void
92 deliver(STAmount const& amount)
93 {
94 // NOLINTNEXTLINE(bugprone-unchecked-optional-access) view_ emplaced in constructor
95 view_->deliver(amount);
96 }
97
101 void
102 discard();
103
108
113 size();
114
118 void
119 visit(
120 std::function<void(
121 uint256 const& key,
122 bool isDelete,
123 SLE::const_ref before,
124 SLE::const_ref after)> const& func);
125
126 void
128 {
129 // NOLINTNEXTLINE(bugprone-unchecked-optional-access) view_ emplaced in constructor
130 view_->rawDestroyXRP(fee);
131 }
132
140 TER
141 checkInvariants(TER const result, XRPAmount const fee);
142
145 {
146 XRPL_ASSERT(
147 view_.has_value(),
148 "xrpl::ApplyContext::getApplyViewContext : view_ emplaced in constructor");
149 return {.view = *view_, .tx = tx};
150 }
151
152private:
153 static TER
154 failInvariantCheck(TER const result);
155
156 template <std::size_t... Is>
157 TER
159
163
164 // The ID of the batch transaction we are executing under, if set.
166};
167
168} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
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
ApplyViewContext getApplyViewContext()
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:134
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
Interface for ledger entry changes.
Definition RawView.h:18
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:572
ApplyFlags
Definition ApplyView.h:27
@ TapBatch
Definition ApplyView.h:42
TERSubset< CanCvtToTER > TER
Definition TER.h:647
BaseUInt< 256 > uint256
Definition base_uint.h:580
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:444