xrpld
Loading...
Searching...
No Matches
MPTInvariant.h
1#pragma once
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/ledger/ReadView.h>
5#include <xrpl/protocol/STLedgerEntry.h>
6#include <xrpl/protocol/STTx.h>
7#include <xrpl/protocol/TER.h>
8
9#include <cstdint>
10#include <memory>
11#include <vector>
12
13namespace xrpl {
14
16{
19
22 // non-MPT transactions may attempt to create
23 // MPToken by an issuer
24 bool mptCreatedByIssuer_ = false;
25
29
32
37
38public:
47 void
48 visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after);
49
60 [[nodiscard]] bool
62 STTx const& tx,
63 TER const result,
64 XRPAmount const fee,
65 ReadView const& view,
66 beast::Journal const& j) const;
67};
68
77{
78 enum class Order { Before = 0, After = 1 };
79 struct MPTData
80 {
82 // sum (MPT after - MPT before)
84 };
85
86 // true if OutstandingAmount > MaximumAmount in after for any MPT
87 bool overflow_{false};
88 // mptid:MPTData
90
91public:
99 void
100 visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after);
101
112 bool
113 finalize(
114 STTx const& tx,
115 TER const result,
116 XRPAmount const fee,
117 ReadView const& view,
118 beast::Journal const& j);
119};
120
143{
157
158public:
166 void
168 bool isDelete,
169 std::shared_ptr<SLE const> const& before,
171
183 bool
184 finalize(
185 STTx const& tx,
186 TER const result,
187 XRPAmount const fee,
188 ReadView const& view,
189 beast::Journal const& j);
190};
191
193{
199 // MPTID: {holder: Value}
201 // Deleted MPToken
202 // MPToken key: true if MPTAuthorized is set
204
205public:
213 void
215 bool isDelete,
216 std::shared_ptr<SLE const> const& before,
218
229 bool
230 finalize(
231 STTx const& tx,
232 TER const result,
233 XRPAmount const fee,
234 ReadView const& view,
235 beast::Journal const& j);
236
237private:
253 [[nodiscard]] bool
255 ReadView const& view,
256 MPTID const& mptid,
257 AccountID const& holder,
258 bool requireAuth) const;
259};
260
261} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
A view into a ledger.
Definition ReadView.h:31
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.
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_
Verify public MPT amount and outstanding amount accounting.
hash_map< uint192, MPTData > data_
bool finalize(STTx const &tx, TER const result, XRPAmount const fee, ReadView const &view, beast::Journal const &j)
Verify public MPT payment accounting invariants.
void visitEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after)
Track MPT amount and outstanding amount changes.
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:44
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:554
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:28
TERSubset< CanCvtToTER > TER
Definition TER.h:634
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