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/Book.h>
12#include <xrpl/protocol/STAmount.h>
13#include <xrpl/protocol/STTx.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/TxMeta.h>
16#include <xrpl/protocol/XRPAmount.h>
17
18#include <cstddef>
19#include <functional>
20#include <optional>
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::ConstRef before,
124 SLE::ConstRef after)> const& func);
125
126 void
128 {
129 // NOLINTNEXTLINE(bugprone-unchecked-optional-access) view_ emplaced in constructor
130 view_->rawDestroyXRP(fee);
131 }
132
138 void
139 addOrderBook(Book const& book);
140
143 {
144 XRPL_ASSERT(
145 view_.has_value(),
146 "xrpl::ApplyContext::getApplyViewContext : view_ emplaced in constructor");
147 return {.view = *view_, .tx = tx};
148 }
149
150private:
154
155 // The ID of the batch transaction we are executing under, if set.
157};
158
159} // 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
void destroyXRP(XRPAmount const &fee)
XRPAmount const baseFee
ApplyViewContext getApplyViewContext()
void addOrderBook(Book const &book)
Registers a newly-created order book directory with the shared, process-wide OrderBookDB,...
ApplyFlags const & flags() const
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()})
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< UInt256 const > parentBatchId_
std::optional< TxMeta > apply(TER)
Apply the transaction result to the base.
std::optional< ApplyViewImpl > view_
beast::Journal const journal
void visit(std::function< void(UInt256 const &key, bool isDelete, SLE::ConstRef before, SLE::ConstRef after)> const &func)
Visit unapplied changes.
ApplyView const & view() const
RawView & rawView()
ApplyView & view()
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
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:141
Specifies an order book.
Definition Book.h:28
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 & ConstRef
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
BaseUInt< 256 > UInt256
Definition base_uint.h:580
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:644
ApplyFlags
Definition ApplyView.h:27
@ TapBatch
Definition ApplyView.h:42
TERSubset< CanCvtToTER > TER
Definition TER.h:654
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:451