xrpld
Loading...
Searching...
No Matches
ApplyStateTable.h
1#pragma once
2
3#include <xrpl/basics/UnorderedContainers.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/ledger/OpenView.h>
7#include <xrpl/ledger/RawView.h>
8#include <xrpl/ledger/ReadView.h>
9#include <xrpl/protocol/AccountID.h>
10#include <xrpl/protocol/Keylet.h>
11#include <xrpl/protocol/STAmount.h>
12#include <xrpl/protocol/STLedgerEntry.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 <map>
21#include <optional>
22#include <utility>
23
24namespace xrpl::detail {
25
26// Helper class that buffers modifications
28{
29public:
31
32private:
33 enum class Action {
38 };
39
41
44
45public:
46 ApplyStateTable() = default;
48
53 operator=(ApplyStateTable const&) = delete;
54
55 void
56 apply(RawView& to) const;
57
59 apply(
60 OpenView& to,
61 STTx const& tx,
62 TER ter,
63 std::optional<STAmount> const& deliver,
64 std::optional<uint256 const> const& parentBatchId,
65 bool isDryRun,
67
68 [[nodiscard]] bool
69 exists(ReadView const& base, Keylet const& k) const;
70
71 [[nodiscard]] std::optional<key_type>
72 succ(ReadView const& base, key_type const& key, std::optional<key_type> const& last) const;
73
74 [[nodiscard]] SLE::const_pointer
75 read(ReadView const& base, Keylet const& k) const;
76
78 peek(ReadView const& base, Keylet const& k);
79
80 [[nodiscard]] std::size_t
81 size() const;
82
83 void
84 visit(
85 ReadView const& base,
86 std::function<void(
87 uint256 const& key,
88 bool isDelete,
89 SLE::const_ref before,
90 SLE::const_ref after)> const& func) const;
91
92 void
93 erase(ReadView const& base, SLE::ref sle);
94
95 void
96 rawErase(ReadView const& base, SLE::ref sle);
97
98 void
99 insert(ReadView const& base, SLE::ref sle);
100
101 void
102 update(ReadView const& base, SLE::ref sle);
103
104 void
105 replace(ReadView const& base, SLE::ref sle);
106
107 void
108 destroyXRP(XRPAmount const& fee);
109
110 // For debugging
111 [[nodiscard]] XRPAmount const&
113 {
114 return dropsDestroyed_;
115 }
116
117private:
119
120 static void
121 threadItem(TxMeta& meta, SLE::ref to);
122
124 getForMod(ReadView const& base, key_type const& key, Mods& mods, beast::Journal j);
125
126 void
127 threadTx(ReadView const& base, TxMeta& meta, AccountID const& to, Mods& mods, beast::Journal j);
128
129 void
131 ReadView const& base,
132 TxMeta& meta,
133 SLE::const_ref sle,
134 Mods& mods,
136};
137
138} // namespace xrpl::detail
A generic endpoint for log messages.
Definition Journal.h:44
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
Interface for ledger entry changes.
Definition RawView.h:18
A view into a ledger.
Definition ReadView.h:41
uint256 key_type
Definition ReadView.h:45
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & const_ref
std::shared_ptr< STLedgerEntry const > const_pointer
SLE::const_pointer read(ReadView const &base, Keylet const &k) const
void destroyXRP(XRPAmount const &fee)
bool exists(ReadView const &base, Keylet const &k) const
std::map< key_type, std::pair< Action, SLE::pointer > > items_t
void replace(ReadView const &base, SLE::ref sle)
XRPAmount const & dropsDestroyed() const
void insert(ReadView const &base, SLE::ref sle)
void visit(ReadView const &base, std::function< void(uint256 const &key, bool isDelete, SLE::const_ref before, SLE::const_ref after)> const &func) const
SLE::pointer peek(ReadView const &base, Keylet const &k)
SLE::pointer getForMod(ReadView const &base, key_type const &key, Mods &mods, beast::Journal j)
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
void threadTx(ReadView const &base, TxMeta &meta, AccountID const &to, Mods &mods, beast::Journal j)
void threadOwners(ReadView const &base, TxMeta &meta, SLE::const_ref sle, Mods &mods, beast::Journal j)
ApplyStateTable & operator=(ApplyStateTable const &)=delete
void rawErase(ReadView const &base, SLE::ref sle)
void apply(RawView &to) const
void update(ReadView const &base, SLE::ref sle)
ApplyStateTable & operator=(ApplyStateTable &&)=delete
hash_map< key_type, SLE::pointer > Mods
static void threadItem(TxMeta &meta, SLE::ref to)
ApplyStateTable(ApplyStateTable const &)=delete
ApplyStateTable(ApplyStateTable &&)=default
void erase(ReadView const &base, SLE::ref sle)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:572
std::unordered_map< Key, Value, Hash, Pred, Allocator > hash_map
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:647
BaseUInt< 256 > uint256
Definition base_uint.h:580
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20