xrpld
Loading...
Searching...
No Matches
xrpl::ValidVault Class Reference

#include <VaultInvariant.h>

Collaboration diagram for xrpl::ValidVault:

Classes

struct  Vault
struct  Shares
struct  DeltaInfo

Public Member Functions

void visitEntry (bool, SLE::const_ref, SLE::const_ref)
bool finalize (STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)

Static Public Member Functions

static std::int32_t computeCoarsestScale (std::vector< DeltaInfo > const &numbers)

Private Member Functions

std::int32_t computeVaultMinScale (DeltaInfo const &vaultDelta, Rules const &rules) const
 Compute the minimum STAmount scale for rounding invariant calculations.
std::optional< DeltaInfodeltaAssets (AccountID const &id) const
 Return the vault-asset balance-change delta for an account.
std::optional< DeltaInfodeltaAssetsTxAccount (STTx const &tx, XRPAmount fee) const
 Return the vault-asset delta for the transaction's sending account, adjusted for the fee.
std::optional< DeltaInfodeltaShares (AccountID const &id) const
 Return the vault-share balance-change delta for an account.

Static Private Member Functions

static bool isVaultEmpty (Vault const &vault)
 Check whether a vault holds no assets.

Private Attributes

std::vector< VaultafterVault_
std::vector< SharesafterMPTs_
std::vector< VaultbeforeVault_
std::vector< SharesbeforeMPTs_
std::unordered_map< uint256, DeltaInfodeltas_

Static Private Attributes

static constexpr Number kZero {}

Detailed Description

Definition at line 38 of file VaultInvariant.h.

Member Function Documentation

◆ computeVaultMinScale()

std::int32_t xrpl::ValidVault::computeVaultMinScale ( DeltaInfo const & vaultDelta,
Rules const & rules ) const
nodiscardprivate

Compute the minimum STAmount scale for rounding invariant calculations.

Post-amendment (fixCleanup3_2_0) this is simply the posterior assetsTotal scale. Pre-amendment it is the coarsest scale across vaultDelta and both asset-field deltas.

Parameters
vaultDeltaDelta of the vault's asset balance for this transaction.
rulesActive ledger rules (used to check the amendment).
Returns
The minimum scale to apply when rounding vault-related amounts.

Definition at line 255 of file VaultInvariant.cpp.

◆ deltaAssets()

std::optional< ValidVault::DeltaInfo > xrpl::ValidVault::deltaAssets ( AccountID const & id) const
nodiscardprivate

Return the vault-asset balance-change delta for an account.

Looks up the ledger-entry delta recorded during visitEntry for the account entry (XRP), trust line (IOU), or MPToken (MPT) that corresponds to the vault asset held by id.

Parameters
idAccount whose asset delta is requested.
Returns
The delta, or std::nullopt if the entry was not touched.

Definition at line 186 of file VaultInvariant.cpp.

◆ deltaAssetsTxAccount()

std::optional< ValidVault::DeltaInfo > xrpl::ValidVault::deltaAssetsTxAccount ( STTx const & tx,
XRPAmount fee ) const
nodiscardprivate

Return the vault-asset delta for the transaction's sending account, adjusted for the fee.

Calls deltaAssets for tx[sfAccount] and, for non-delegated XRP transactions, adds the consumed fee back so the invariant sees the net asset movement rather than the fee-reduced balance change.

Parameters
txThe transaction being applied.
feeFee charged by this transaction.
Returns
The fee-adjusted delta, or std::nullopt if the net delta is zero or the account entry was not touched.

Definition at line 218 of file VaultInvariant.cpp.

◆ deltaShares()

std::optional< ValidVault::DeltaInfo > xrpl::ValidVault::deltaShares ( AccountID const & id) const
nodiscardprivate

Return the vault-share balance-change delta for an account.

For the vault's pseudo-account the MPTokenIssuance outstanding-amount delta is returned; for all other accounts the MPToken delta is returned.

Parameters
idAccount whose share delta is requested.
Returns
The delta, or std::nullopt if the entry was not touched.

Definition at line 236 of file VaultInvariant.cpp.

◆ isVaultEmpty()

bool xrpl::ValidVault::isVaultEmpty ( Vault const & vault)
staticnodiscardprivate

Check whether a vault holds no assets.

Parameters
vaultSnapshot of the vault to test.
Returns
true when both assetsAvailable and assetsTotal are zero.

Definition at line 249 of file VaultInvariant.cpp.

◆ computeCoarsestScale()

std::int32_t xrpl::ValidVault::computeCoarsestScale ( std::vector< DeltaInfo > const & numbers)
staticnodiscard

Definition at line 1080 of file VaultInvariant.cpp.

◆ visitEntry()

void xrpl::ValidVault::visitEntry ( bool isDelete,
SLE::const_ref before,
SLE::const_ref after )

Definition at line 65 of file VaultInvariant.cpp.

◆ finalize()

bool xrpl::ValidVault::finalize ( STTx const & tx,
TER const ret,
XRPAmount const fee,
ReadView const & view,
beast::Journal const & j )

Definition at line 281 of file VaultInvariant.cpp.

Member Data Documentation

◆ kZero

Number xrpl::ValidVault::kZero {}
staticconstexprprivate

Definition at line 40 of file VaultInvariant.h.

◆ afterVault_

std::vector<Vault> xrpl::ValidVault::afterVault_
private

Definition at line 78 of file VaultInvariant.h.

◆ afterMPTs_

std::vector<Shares> xrpl::ValidVault::afterMPTs_
private

Definition at line 79 of file VaultInvariant.h.

◆ beforeVault_

std::vector<Vault> xrpl::ValidVault::beforeVault_
private

Definition at line 80 of file VaultInvariant.h.

◆ beforeMPTs_

std::vector<Shares> xrpl::ValidVault::beforeMPTs_
private

Definition at line 81 of file VaultInvariant.h.

◆ deltas_

std::unordered_map<uint256, DeltaInfo> xrpl::ValidVault::deltas_
private

Definition at line 82 of file VaultInvariant.h.