Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/xrpl/ledger/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/MPTokenIssuanceEntry.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Keylet.h>
Expand Down Expand Up @@ -83,7 +84,7 @@ isVaultPseudoAccountFrozen(
isVaultPseudoAccountFrozen(
ReadView const& view,
AccountID const& account,
SLE const& issuanceSle,
MPTokenIssuanceEntryR const& issuanceSle,
std::uint8_t depth);

[[nodiscard]] bool
Expand Down
6 changes: 3 additions & 3 deletions include/xrpl/ledger/helpers/EscrowHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/MPTokenIssuanceEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/MPTokenHelpers.h>
#include <xrpl/ledger/helpers/RippleStateHelpers.h>
Expand Down Expand Up @@ -140,7 +141,7 @@ escrowLockPreclaimHelper<MPTIssue>(

// If the mpt does not exist, return tecOBJECT_NOT_FOUND
auto const issuanceKey = keylet::mptokenIssuance(amount.get<MPTIssue>().getMptID());
auto const sleIssuance = view.read(issuanceKey);
MPTokenIssuanceEntryR const sleIssuance(issuanceKey, view);
if (!sleIssuance)
return tecOBJECT_NOT_FOUND;

Expand Down Expand Up @@ -296,8 +297,7 @@ escrowUnlockPreclaimHelper<MPTIssue>(
return tesSUCCESS;

// If the mpt does not exist, return tecOBJECT_NOT_FOUND
auto const issuanceKey = keylet::mptokenIssuance(amount.get<MPTIssue>().getMptID());
auto const sleIssuance = view.read(issuanceKey);
MPTokenIssuanceEntryR const sleIssuance(amount.get<MPTIssue>().getMptID(), view);
if (!sleIssuance)
return tecOBJECT_NOT_FOUND;

Expand Down
7 changes: 4 additions & 3 deletions include/xrpl/ledger/helpers/MPTokenHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/MPTokenIssuanceEntry.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
Expand Down Expand Up @@ -30,7 +31,7 @@ namespace xrpl {
isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue);

[[nodiscard]] bool
isGlobalFrozen(SLE const& issuanceSle);
isGlobalFrozen(MPTokenIssuanceEntryR const& issuanceSle);

/**
* Returns true if @p account's MPToken for @p mptIssue carries the
Expand Down Expand Up @@ -179,7 +180,7 @@ enforceMPTokenAuthorization(
* @return The underlying Asset (MPTIssue or Issue).
*/
[[nodiscard]] Asset
assetOfHolding(SLE const& sleShareIssuance, SLE const& sleHolding);
assetOfHolding(MPTokenIssuanceEntryR const& sleShareIssuance, SLE const& sleHolding);

/**
* Check whether @p to may receive the given MPT from @p from.
Expand Down Expand Up @@ -330,7 +331,7 @@ maxMPTAmount(ReadView const& view, MPTID const& mptID);
* But available amount is always <= |MaximumAmount - OutstandingAmount|.
*/
std::int64_t
availableMPTAmount(SLE const& sleIssuance);
availableMPTAmount(MPTokenIssuanceEntryR const& sleIssuance);

std::int64_t
availableMPTAmount(ReadView const& view, MPTID const& mptID);
Expand Down
22 changes: 16 additions & 6 deletions include/xrpl/ledger/helpers/VaultHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <xrpl/basics/Number.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/MPTokenIssuanceEntry.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Asset.h>
#include <xrpl/protocol/Protocol.h>
Expand Down Expand Up @@ -259,7 +260,10 @@ vaultOpenZoneCapacity(SLE::ConstRef vault, Number const& roundedAmount);
* @return The number of shares, or nullopt on error.
*/
[[nodiscard]] std::optional<STAmount>
assetsToSharesDeposit(SLE::ConstRef vault, SLE::ConstRef issuance, STAmount const& assets);
assetsToSharesDeposit(
SLE::ConstRef vault,
MPTokenIssuanceEntryR const& issuance,
STAmount const& assets);

/**
* From the perspective of a vault, return the number of assets to take from
Expand All @@ -273,7 +277,10 @@ assetsToSharesDeposit(SLE::ConstRef vault, SLE::ConstRef issuance, STAmount cons
* @return The number of assets, or nullopt on error.
*/
[[nodiscard]] std::optional<STAmount>
sharesToAssetsDeposit(SLE::ConstRef vault, SLE::ConstRef issuance, STAmount const& shares);
sharesToAssetsDeposit(
SLE::ConstRef vault,
MPTokenIssuanceEntryR const& issuance,
STAmount const& shares);

/**
* Adjusts a requested asset change (delta) to match the decimal scale of the
Expand Down Expand Up @@ -427,7 +434,7 @@ checkDebitNotDust(
[[nodiscard]] std::optional<STAmount>
assetsToSharesWithdraw(
SLE::ConstRef vault,
SLE::ConstRef issuance,
MPTokenIssuanceEntryR const& issuance,
STAmount const& assets,
TruncateShares truncate = TruncateShares::No,
WaiveUnrealizedLoss waive = WaiveUnrealizedLoss::No);
Expand All @@ -448,7 +455,7 @@ assetsToSharesWithdraw(
[[nodiscard]] std::optional<STAmount>
sharesToAssetsWithdraw(
SLE::ConstRef vault,
SLE::ConstRef issuance,
MPTokenIssuanceEntryR const& issuance,
STAmount const& shares,
WaiveUnrealizedLoss waive = WaiveUnrealizedLoss::No);

Expand All @@ -463,7 +470,10 @@ sharesToAssetsWithdraw(
* both the share MPTID and the outstanding-amount total.
*/
[[nodiscard]] bool
isSoleShareholder(ReadView const& view, AccountID const& account, SLE::ConstRef issuance);
isSoleShareholder(
ReadView const& view,
AccountID const& account,
MPTokenIssuanceEntryR const& issuance);

/**
* Resolves a Vault's LEVersion.
Expand Down Expand Up @@ -620,7 +630,7 @@ enum class SuppressExpired : bool { No = false, Yes = true };
[[nodiscard]] TER
checkVaultDomain(
ReadView const& view,
SLE::ConstRef issuance,
MPTokenIssuanceEntryR const& issuance,
AccountID const& subject,
SuppressExpired suppressExpired);

Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/tx/transactors/vault/VaultClawback.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/core/ServiceRegistry.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/entries/MPTokenIssuanceEntry.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STTx.h>
Expand Down Expand Up @@ -49,7 +50,7 @@ class VaultClawback : public Transactor
std::expected<std::pair<STAmount, STAmount>, TER>
assetsToClawback(
SLE::Ref vault,
SLE::ConstRef sleShareIssuance,
MPTokenIssuanceEntryR const& sleShareIssuance,
AccountID const& holder,
STAmount const& clawbackAmount);
};
Expand Down
19 changes: 10 additions & 9 deletions src/libxrpl/ledger/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <xrpl/ledger/entries/AmendmentsEntry.h>
#include <xrpl/ledger/entries/DepositPreauthEntry.h>
#include <xrpl/ledger/entries/LedgerHashesEntry.h>
#include <xrpl/ledger/entries/MPTokenIssuanceEntry.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/CredentialHelpers.h>
#include <xrpl/ledger/helpers/DirectoryHelpers.h>
Expand Down Expand Up @@ -89,24 +90,24 @@ bool
isVaultPseudoAccountFrozenForIssuance(
ReadView const& view,
AccountID const& account,
SLE const& issuanceSle,
MPTokenIssuanceEntryR const& issuanceSle,
std::uint8_t depth)
{
XRPL_ASSERT(
issuanceSle.getType() == ltMPTOKEN_ISSUANCE,
issuanceSle->getType() == ltMPTOKEN_ISSUANCE,
"xrpl::isVaultPseudoAccountFrozenForIssuance : MPTokenIssuance SLE");

auto const issuer = issuanceSle.getAccountID(sfIssuer);
auto const issuer = issuanceSle->getAccountID(sfIssuer);

// Post-fixCleanup3_2_0: vault shares carry sfReferenceHolding pointing
// to the vault pseudo's MPToken or RippleState for the underlying.
// Read it to derive the underlying asset and recurse, skipping the
// issuer-account-then-vault chain. Pre-amendment shares (no field)
// fall back to the chain lookup below.
if (issuanceSle.isFieldPresent(sfReferenceHolding))
if (issuanceSle->isFieldPresent(sfReferenceHolding))
{
auto const sleHolding =
view.read(keylet::unchecked(issuanceSle.getFieldH256(sfReferenceHolding)));
view.read(keylet::unchecked(issuanceSle->getFieldH256(sfReferenceHolding)));
if (!sleHolding)
{
// LCOV_EXCL_START
Expand Down Expand Up @@ -153,18 +154,18 @@ isVaultPseudoAccountFrozen(
if (auto const result = checkVaultPseudoAccountFrozenPreconditions(view, depth))
return *result;

auto const issuanceSle = view.read(keylet::mptokenIssuance(mptShare.getMptID()));
if (issuanceSle == nullptr)
MPTokenIssuanceEntryR const issuanceSle(mptShare.getMptID(), view);
if (!issuanceSle)
return false; // zero MPToken won't block deletion of MPTokenIssuance

return isVaultPseudoAccountFrozenForIssuance(view, account, *issuanceSle, depth);
return isVaultPseudoAccountFrozenForIssuance(view, account, issuanceSle, depth);
}

bool
isVaultPseudoAccountFrozen(
ReadView const& view,
AccountID const& account,
SLE const& issuanceSle,
MPTokenIssuanceEntryR const& issuanceSle,
std::uint8_t depth)
{
if (auto const result = checkVaultPseudoAccountFrozenPreconditions(view, depth))
Expand Down
Loading
Loading