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
57 // viewRef_ points into view_, so a copied or moved context would alias the original.
58 ApplyContext(ApplyContext const&) = delete;
60
62 STTx const& tx;
66
69 {
70 return viewRef_.get();
71 }
72
73 [[nodiscard]] ApplyView const&
74 view() const
75 {
76 return viewRef_.get();
77 }
78
79 // VFALCO Unfortunately this is necessary
80 RawView&
82 {
83 return viewRef_.get();
84 }
85
86 [[nodiscard]] ApplyFlags const&
87 flags() const
88 {
89 return flags_;
90 }
91
95 void
96 deliver(STAmount const& amount)
97 {
98 viewRef_.get().deliver(amount);
99 }
100
104 void
105 discard();
106
111
116 size();
117
121 void
122 visit(
123 std::function<void(
124 UInt256 const& key,
125 bool isDelete,
126 SLE::ConstRef before,
127 SLE::ConstRef after)> const& func);
128
129 void
131 {
132 viewRef_.get().rawDestroyXRP(fee);
133 }
134
140 void
141 addOrderBook(Book const& book);
142
145 {
146 return {.view = viewRef_.get(), .tx = tx};
147 }
148
149private:
152
153 // view_ and viewRef_ always represent the same view. Update viewRef_ whenever view_ is
154 // re-emplaced.
157
158 // The ID of the batch transaction we are executing under, if set.
160};
161
162} // 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
ApplyContext(ApplyContext const &)=delete
void deliver(STAmount const &amount)
Sets the DeliveredAmount field in the metadata.
std::optional< UInt256 const > parentBatchId_
ApplyContext(ApplyContext &&)=delete
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
std::reference_wrapper< ApplyViewImpl > viewRef_
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:581
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:668
ApplyFlags
Definition ApplyView.h:27
@ TapBatch
Definition ApplyView.h:42
TERSubset< CanCvtToTER > TER
Definition TER.h:657
Bundles the mutable ledger view and the transaction being applied.
Definition ApplyView.h:451