pass by reference

This commit is contained in:
Mayukha Vadari
2026-06-25 22:16:29 -05:00
parent 1a2a7e93d1
commit 88ae2bb91c
14 changed files with 35 additions and 28 deletions

View File

@@ -201,7 +201,7 @@ canWithdraw(ReadView const& view, STTx const& tx);
[[nodiscard]] TER
doWithdraw(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& senderAcct,
AccountID const& dstAcct,
AccountID const& sourceAcct,

View File

@@ -71,7 +71,7 @@ canAddHolding(ReadView const& view, MPTIssue const& mptIssue);
[[nodiscard]] TER
authorizeMPToken(
ApplyViewContext ctx,
ApplyViewContext& ctx,
XRPAmount const& priorBalance,
MPTID const& mptIssuanceID,
AccountID const& account,
@@ -102,7 +102,7 @@ requireAuth(
*/
[[nodiscard]] TER
enforceMPTokenAuthorization(
ApplyViewContext ctx,
ApplyViewContext& ctx,
MPTID const& mptIssuanceID,
AccountID const& account,
XRPAmount const& priorBalance,
@@ -188,7 +188,7 @@ canMPTTradeAndTransfer(
[[nodiscard]] TER
addEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
XRPAmount priorBalance,
MPTIssue const& mptIssue,
@@ -196,7 +196,7 @@ addEmptyHolding(
[[nodiscard]] TER
removeEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
MPTIssue const& mptIssue,
beast::Journal journal);

View File

@@ -229,7 +229,7 @@ canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, Acc
/// canAddHolding() in preflight with the same View and Asset
[[nodiscard]] TER
addEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
XRPAmount priorBalance,
Issue const& issue,
@@ -237,7 +237,7 @@ addEmptyHolding(
[[nodiscard]] TER
removeEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
Issue const& issue,
beast::Journal journal);

View File

@@ -230,7 +230,7 @@ canAddHolding(ReadView const& view, Asset const& asset);
[[nodiscard]] TER
addEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
XRPAmount priorBalance,
Asset const& asset,
@@ -238,7 +238,7 @@ addEmptyHolding(
[[nodiscard]] TER
removeEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
Asset const& asset,
beast::Journal journal);

View File

@@ -112,10 +112,10 @@ public:
TER
checkInvariants(TER const result, XRPAmount const fee);
inline ApplyViewContext
inline ApplyViewContext&
getApplyViewContext()
{
return {view(), tx};
return viewCtx_;
}
private:
@@ -132,6 +132,11 @@ private:
// The ID of the batch transaction we are executing under, if seated.
std::optional<uint256 const> parentBatchId_;
// A temporary helper object that passes around ApplyContext info
// Only necessary (for now) because the ApplyContext can't be passed into helpers due to
// levelization
ApplyViewContext viewCtx_;
};
} // namespace xrpl

View File

@@ -432,7 +432,7 @@ canWithdraw(ReadView const& view, STTx const& tx)
TER
doWithdraw(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& senderAcct,
AccountID const& dstAcct,
AccountID const& sourceAcct,

View File

@@ -126,7 +126,7 @@ canAddHolding(ReadView const& view, MPTIssue const& mptIssue)
[[nodiscard]] TER
addEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
XRPAmount priorBalance,
MPTIssue const& mptIssue,
@@ -148,7 +148,7 @@ addEmptyHolding(
[[nodiscard]] TER
authorizeMPToken(
ApplyViewContext ctx,
ApplyViewContext& ctx,
XRPAmount const& priorBalance,
MPTID const& mptIssuanceID,
AccountID const& account,
@@ -280,7 +280,7 @@ authorizeMPToken(
[[nodiscard]] TER
removeEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
MPTIssue const& mptIssue,
beast::Journal journal)
@@ -411,7 +411,7 @@ requireAuth(
[[nodiscard]] TER
enforceMPTokenAuthorization(
ApplyViewContext ctx,
ApplyViewContext& ctx,
MPTID const& mptIssuanceID,
AccountID const& account,
XRPAmount const& priorBalance, // for MPToken authorization

View File

@@ -634,7 +634,7 @@ canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, Acc
TER
addEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
XRPAmount priorBalance,
Issue const& issue,
@@ -699,7 +699,7 @@ addEmptyHolding(
TER
removeEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
Issue const& issue,
beast::Journal journal)

View File

@@ -474,7 +474,7 @@ canAddHolding(ReadView const& view, Asset const& asset)
TER
addEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
XRPAmount priorBalance,
Asset const& asset,
@@ -489,7 +489,7 @@ addEmptyHolding(
TER
removeEmptyHolding(
ApplyViewContext ctx,
ApplyViewContext& ctx,
AccountID const& accountID,
Asset const& asset,
beast::Journal journal)

View File

@@ -40,12 +40,13 @@ ApplyContext::ApplyContext(
, journal(journal)
, base_(base)
, flags_(flags)
, view_{std::in_place, &base_, flags_}
, parentBatchId_(parentBatchId)
, viewCtx_{*view_, tx}
{
XRPL_ASSERT(
parentBatchId.has_value() == ((flags_ & TapBatch) == TapBatch),
"Parent Batch ID should be set if batch apply flag is set");
view_.emplace(&base_, flags_);
}
void

View File

@@ -159,7 +159,7 @@ LoanBrokerDelete::doApply()
return ter;
}
if (auto ter = removeEmptyHolding({view(), tx}, brokerPseudoID, vaultAsset, j_))
if (auto ter = removeEmptyHolding(ctx_.getApplyViewContext(), brokerPseudoID, vaultAsset, j_))
return ter;
auto brokerPseudoSLE = view().peek(keylet::account(brokerPseudoID));

View File

@@ -399,7 +399,8 @@ VaultClawback::doApply()
// Keep MPToken if holder is the vault owner.
if (holder != vault->at(sfOwner))
{
if (auto const ter = removeEmptyHolding({view(), tx}, holder, sharesDestroyed.asset(), j_);
if (auto const ter =
removeEmptyHolding(ctx_.getApplyViewContext(), holder, sharesDestroyed.asset(), j_);
isTesSuccess(ter))
{
JLOG(j_.debug()) //

View File

@@ -94,7 +94,7 @@ VaultDelete::doApply()
// Destroy the asset holding.
auto asset = vault->at(sfAsset);
if (auto ter = removeEmptyHolding({view(), ctx_.tx}, vault->at(sfAccount), asset, j_);
if (auto ter = removeEmptyHolding(ctx_.getApplyViewContext(), vault->at(sfAccount), asset, j_);
!isTesSuccess(ter))
return ter;
@@ -123,8 +123,8 @@ VaultDelete::doApply()
// Try to remove MPToken for vault shares for the vault owner if it exists.
if (auto const mptoken = view().peek(keylet::mptoken(shareMPTID, accountID_)))
{
if (auto const ter =
removeEmptyHolding({view(), ctx_.tx}, accountID_, MPTIssue(shareMPTID), j_);
if (auto const ter = removeEmptyHolding(
ctx_.getApplyViewContext(), accountID_, MPTIssue(shareMPTID), j_);
!isTesSuccess(ter))
{
// LCOV_EXCL_START

View File

@@ -347,8 +347,8 @@ VaultWithdraw::doApply()
// Keep MPToken if holder is the vault owner.
if (accountID_ != vault->at(sfOwner))
{
if (auto const ter =
removeEmptyHolding({view(), ctx_.tx}, accountID_, sharesRedeemed.asset(), j_);
if (auto const ter = removeEmptyHolding(
ctx_.getApplyViewContext(), accountID_, sharesRedeemed.asset(), j_);
isTesSuccess(ter))
{
JLOG(j_.debug()) //