xrpld
Loading...
Searching...
No Matches
ApplyContext.cpp
1#include <xrpl/tx/ApplyContext.h>
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/OpenView.h>
9#include <xrpl/ledger/OrderBookDB.h>
10#include <xrpl/protocol/Book.h>
11#include <xrpl/protocol/STTx.h>
12#include <xrpl/protocol/TER.h>
13#include <xrpl/protocol/TxMeta.h>
14#include <xrpl/protocol/XRPAmount.h>
15
16#include <cstddef>
17#include <functional>
18#include <optional>
19
20namespace xrpl {
21
24 OpenView& base,
25 std::optional<UInt256 const> const& parentBatchId,
26 STTx const& tx,
32 , tx(tx)
36 , base_(base)
37 , flags_(flags)
38 , parentBatchId_(parentBatchId)
39{
40 XRPL_ASSERT(
41 parentBatchId.has_value() == ((flags_ & TapBatch) == TapBatch),
42 "Parent Batch ID should be set if batch apply flag is set");
43 view_.emplace(&base_, flags_);
44}
45
46void
48{
49 view_.emplace(&base_, flags_);
50}
51
54{
55 // NOLINTNEXTLINE(bugprone-unchecked-optional-access) view_ emplaced in constructor
56 return view_->apply(base_, tx, ter, parentBatchId_, (flags_ & TapDryRun) != 0u, journal);
57}
58
59void
61{
62 if ((flags_ & TapDryRun) == TapNone)
63 registry.get().getOrderBookDB().addOrderBook(book);
64}
65
68{
69 return view_->size(); // NOLINT(bugprone-unchecked-optional-access)
70}
71
72void
74 std::function<void(UInt256 const&, bool, SLE::ConstRef, SLE::ConstRef)> const& func)
75{
76 view_->visit(base_, func); // NOLINT(bugprone-unchecked-optional-access)
77}
78
79} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
std::size_t size()
Get the number of unapplied changes.
STTx const & tx
XRPAmount const baseFee
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
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.
TER const preclaimResult
Specifies an order book.
Definition Book.h:28
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
std::shared_ptr< STLedgerEntry const > const & ConstRef
Service registry for dependency injection.
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
ApplyFlags
Definition ApplyView.h:27
@ TapDryRun
Definition ApplyView.h:46
@ TapNone
Definition ApplyView.h:28
@ TapBatch
Definition ApplyView.h:42
TERSubset< CanCvtToTER > TER
Definition TER.h:654
T has_value(T... args)