xrpld
Loading...
Searching...
No Matches
MPTInvariant.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/ReadView.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/STLedgerEntry.h>
9#include <xrpl/protocol/STTx.h>
10#include <xrpl/protocol/TER.h>
11#include <xrpl/protocol/UintTypes.h>
12#include <xrpl/protocol/XRPAmount.h>
13
14#include <array>
15#include <cstdint>
16#include <map>
17#include <memory>
18#include <optional>
19#include <vector>
20
21namespace xrpl {
22
24{
27
30 // non-MPT transactions may attempt to create
31 // MPToken by an issuer
32 bool mptCreatedByIssuer_ = false;
33
39
44
51
52public:
61 void
62 visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after);
63
74 [[nodiscard]] bool
76 STTx const& tx,
77 TER const result,
78 XRPAmount const fee,
79 ReadView const& view,
80 beast::Journal const& j) const;
81};
82
91{
92 enum class Order { Before = 0, After = 1 };
93 struct MPTData
94 {
96 // sum (MPT after - MPT before)
98 };
99
100 // true if OutstandingAmount > MaximumAmount in after for any MPT
101 bool overflow_{false};
102 // mptid:MPTData
104
105public:
113 void
114 visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after);
115
126 bool
127 finalize(
128 STTx const& tx,
129 TER const result,
130 XRPAmount const fee,
131 ReadView const& view,
132 beast::Journal const& j);
133};
134
157{
171
172public:
180 void
182 bool isDelete,
183 std::shared_ptr<SLE const> const& before,
185
197 bool
198 finalize(
199 STTx const& tx,
200 TER const result,
201 XRPAmount const fee,
202 ReadView const& view,
203 beast::Journal const& j);
204};
205
207{
213 // MPTID: {holder: Value}
215 // Deleted MPToken
216 // MPToken key: true if MPTAuthorized is set
218
219public:
227 void
229 bool isDelete,
230 std::shared_ptr<SLE const> const& before,
232
243 bool
244 finalize(
245 STTx const& tx,
246 TER const result,
247 XRPAmount const fee,
248 ReadView const& view,
249 beast::Journal const& j);
250
251private:
267 [[nodiscard]] bool
269 ReadView const& view,
270 MPTID const& mptid,
271 AccountID const& holder,
272 bool requireAuth) const;
273};
274
275} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry const > const & const_ref
std::shared_ptr< STLedgerEntry const > const_pointer
Invariants: Confidential MPToken consistency.
std::map< uint192, Changes > changes_
void visitEntry(bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)
Track confidential MPT balance, issuance, and version changes.
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
Verify confidential MPT accounting and encrypted-field invariants.
Verify public MPT amount and outstanding amount accounting.
void visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
Track MPT amount and outstanding amount changes.
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
Verify public MPT payment accounting invariants.
hash_map< uint192, MPTData > data_
std::uint32_t mptokensCreated_
bool referenceHoldingSetOnCreate_
sfReferenceHolding is intended to be set exactly once at vault creation and immutable thereafter; tru...
std::uint32_t mptokensDeleted_
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j) const
Verify MPT issuance invariants after transaction application.
bool referenceHoldingMutated_
True when sfReferenceHolding was mutated on an existing MPTokenIssuance.
std::uint32_t mptIssuancesCreated_
void visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
Track MPT issuance and holding creations, deletions, and mutations.
std::vector< std::shared_ptr< SLE const > > deletedHoldings_
MPTokens and RippleStates deleted during apply.
std::uint32_t mptIssuancesDeleted_
hash_map< uint256, bool > deletedAuthorized_
bool isAuthorized(ReadView const &view, MPTID const &mptid, AccountID const &holder, bool requireAuth) const
Check whether a holder is authorized to send or receive an MPToken.
hash_map< uint192, hash_map< AccountID, Value > > amount_
void visitEntry(bool isDelete, std::shared_ptr< SLE const > const &before, std::shared_ptr< SLE const > const &after)
Track MPT balance changes and deleted authorization state.
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
Verify MPT transfer authorization invariants.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition UintTypes.h:54
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
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, std::uint8_t depth=0)
Check if the account lacks required authorization for MPT.
std::array< std::int64_t, 2 > outstanding
std::optional< std::uint64_t > amtAfter
std::optional< std::uint64_t > amtBefore