remove local variables

This commit is contained in:
Mayukha Vadari
2026-07-01 16:18:44 -04:00
parent bf73446528
commit a12cdff58e
4 changed files with 67 additions and 74 deletions

View File

@@ -47,7 +47,6 @@ escrowUnlockApplyHelper<Issue>(
bool const recvLow = issuer > receiver;
bool const senderIssuer = issuer == sender;
bool const receiverIssuer = issuer == receiver;
auto& view = ctx.view;
if (senderIssuer)
return tecINTERNAL; // LCOV_EXCL_LINE
@@ -55,7 +54,7 @@ escrowUnlockApplyHelper<Issue>(
if (receiverIssuer)
return tesSUCCESS;
if (!view.exists(trustLineKey) && createAsset)
if (!ctx.view.exists(trustLineKey) && createAsset)
{
// Can the account cover the trust line's reserve?
auto const sponsorSle = getTxReserveSponsor(ctx);
@@ -63,7 +62,7 @@ escrowUnlockApplyHelper<Issue>(
return sponsorSle.error(); // LCOV_EXCL_LINE
if (auto const ret = checkInsufficientReserve(
view, ctx.tx, sleDest, xrpBalance, *sponsorSle, 1, 0, journal);
ctx.view, ctx.tx, sleDest, xrpBalance, *sponsorSle, 1, 0, journal);
!isTesSuccess(ret))
{
JLOG(journal.trace()) << "Trust line does not exist. "
@@ -77,7 +76,7 @@ escrowUnlockApplyHelper<Issue>(
initialBalance.get<Issue>().account = noAccount();
if (TER const ter = trustCreate(
view, // payment sandbox
ctx.view, // payment sandbox
recvLow, // is dest low?
issuer, // source
receiver, // destination
@@ -98,13 +97,13 @@ escrowUnlockApplyHelper<Issue>(
return ter; // LCOV_EXCL_LINE
}
view.update(sleDest);
ctx.view.update(sleDest);
}
if (!view.exists(trustLineKey) && !receiverIssuer)
if (!ctx.view.exists(trustLineKey) && !receiverIssuer)
return tecNO_LINE;
auto const xferRate = transferRate(view, amount);
auto const xferRate = transferRate(ctx.view, amount);
// update if issuer rate is less than locked rate
if (xferRate < lockedRate)
lockedRate = xferRate;
@@ -132,7 +131,7 @@ escrowUnlockApplyHelper<Issue>(
// of the funds
if (!createAsset)
{
auto const sleRippleState = view.peek(trustLineKey);
auto const sleRippleState = ctx.view.peek(trustLineKey);
if (!sleRippleState)
return tecINTERNAL; // LCOV_EXCL_LINE
@@ -158,7 +157,7 @@ escrowUnlockApplyHelper<Issue>(
// if destination is not the issuer then transfer funds
if (!receiverIssuer)
{
auto const ter = directSendNoFee(view, issuer, receiver, finalAmt, true, journal);
auto const ter = directSendNoFee(ctx.view, issuer, receiver, finalAmt, true, journal);
if (!isTesSuccess(ter))
return ter; // LCOV_EXCL_LINE
}
@@ -181,38 +180,37 @@ escrowUnlockApplyHelper<MPTIssue>(
{
bool const senderIssuer = issuer == sender;
bool const receiverIssuer = issuer == receiver;
auto& view = ctx.view;
auto const mptID = amount.get<MPTIssue>().getMptID();
auto const issuanceKey = keylet::mptIssuance(mptID);
auto const mptKeylet = keylet::mptoken(issuanceKey.key, receiver);
if (!view.exists(mptKeylet) && createAsset && !receiverIssuer)
if (!ctx.view.exists(mptKeylet) && createAsset && !receiverIssuer)
{
auto const sponsorSle = getTxReserveSponsor(ctx);
if (!sponsorSle)
return sponsorSle.error(); // LCOV_EXCL_LINE
if (auto const ret = checkInsufficientReserve(
view, ctx.tx, sleDest, xrpBalance, *sponsorSle, 1, 0, journal);
ctx.view, ctx.tx, sleDest, xrpBalance, *sponsorSle, 1, 0, journal);
!isTesSuccess(ret))
return ret;
if (auto const ter = createMPToken(view, mptID, receiver, *sponsorSle, 0);
if (auto const ter = createMPToken(ctx.view, mptID, receiver, *sponsorSle, 0);
!isTesSuccess(ter))
{
return ter; // LCOV_EXCL_LINE
}
// update owner count.
adjustOwnerCount(view, sleDest, *sponsorSle, 1, journal);
auto mptSle = view.peek(mptKeylet);
adjustOwnerCount(ctx.view, sleDest, *sponsorSle, 1, journal);
auto mptSle = ctx.view.peek(mptKeylet);
addSponsorToLedgerEntry(mptSle, *sponsorSle);
}
if (!view.exists(mptKeylet) && !receiverIssuer)
if (!ctx.view.exists(mptKeylet) && !receiverIssuer)
return tecNO_PERMISSION;
auto const xferRate = transferRate(view, amount);
auto const xferRate = transferRate(ctx.view, amount);
// update if issuer rate is less than locked rate
if (xferRate < lockedRate)
lockedRate = xferRate;
@@ -235,11 +233,11 @@ escrowUnlockApplyHelper<MPTIssue>(
finalAmt = amount.value() - xferFee;
}
return unlockEscrowMPT(
view,
ctx.view,
sender,
receiver,
finalAmt,
view.rules().enabled(fixTokenEscrowV1) ? amount : finalAmt,
ctx.view.rules().enabled(fixTokenEscrowV1) ? amount : finalAmt,
journal);
}

View File

@@ -133,13 +133,12 @@ addEmptyHolding(
beast::Journal journal)
{
auto const& mptID = mptIssue.getMptID();
auto& view = ctx.view;
auto const mpt = view.peek(keylet::mptIssuance(mptID));
auto const mpt = ctx.view.peek(keylet::mptIssuance(mptID));
if (!mpt)
return tefINTERNAL; // LCOV_EXCL_LINE
if (mpt->isFlag(lsfMPTLocked))
return tefINTERNAL; // LCOV_EXCL_LINE
if (view.peek(keylet::mptoken(mptID, accountID)))
if (ctx.view.peek(keylet::mptoken(mptID, accountID)))
return tecDUPLICATE;
if (accountID == mptIssue.getIssuer())
return tesSUCCESS;
@@ -157,9 +156,7 @@ authorizeMPToken(
std::uint32_t flags,
std::optional<AccountID> holderID)
{
auto& view = ctx.view;
auto const tx = ctx.tx;
auto const sleAcct = view.peek(keylet::account(account));
auto const sleAcct = ctx.view.peek(keylet::account(account));
if (!sleAcct)
return tecINTERNAL; // LCOV_EXCL_LINE
@@ -174,19 +171,19 @@ authorizeMPToken(
if ((flags & tfMPTUnauthorize) != 0u)
{
auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
auto const sleMpt = view.peek(mptokenKey);
auto const sleMpt = ctx.view.peek(mptokenKey);
if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0 ||
(view.rules().enabled(fixCleanup3_1_3) &&
(ctx.view.rules().enabled(fixCleanup3_1_3) &&
(*sleMpt)[~sfLockedAmount].valueOr(0) != 0))
return tecINTERNAL; // LCOV_EXCL_LINE
if (!view.dirRemove(
if (!ctx.view.dirRemove(
keylet::ownerDir(account), (*sleMpt)[sfOwnerNode], sleMpt->key(), false))
return tecINTERNAL; // LCOV_EXCL_LINE
adjustOwnerCountObj(view, sleAcct, sleMpt, -1, journal);
adjustOwnerCountObj(ctx.view, sleAcct, sleMpt, -1, journal);
view.erase(sleMpt);
ctx.view.erase(sleMpt);
return tesSUCCESS;
}
@@ -195,7 +192,7 @@ authorizeMPToken(
// - create the MPToken object for the holder
SLE::pointer sponsorSle;
if (account == tx[sfAccount])
if (account == ctx.tx[sfAccount])
{
auto sle = getTxReserveSponsor(ctx);
if (!sle)
@@ -214,40 +211,40 @@ authorizeMPToken(
if (sponsorSle || ownerCount(sleAcct, journal) >= 2)
{
if (auto const ret = checkInsufficientReserve(
view, tx, sleAcct, priorBalance, sponsorSle, 1, 0, journal);
ctx.view, ctx.tx, sleAcct, priorBalance, sponsorSle, 1, 0, journal);
!isTesSuccess(ret))
return ret;
}
// Defensive check before we attempt to create MPToken for the issuer
auto const mpt = view.read(keylet::mptIssuance(mptIssuanceID));
auto const mpt = ctx.view.read(keylet::mptIssuance(mptIssuanceID));
if (!mpt || mpt->getAccountID(sfIssuer) == account)
{
// LCOV_EXCL_START
UNREACHABLE("xrpl::authorizeMPToken : invalid issuance or issuers token");
if (view.rules().enabled(featureLendingProtocol))
if (ctx.view.rules().enabled(featureLendingProtocol))
return tecINTERNAL;
// LCOV_EXCL_STOP
}
auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
auto mptoken = std::make_shared<SLE>(mptokenKey);
if (auto ter = dirLink(view, account, mptoken))
if (auto ter = dirLink(ctx.view, account, mptoken))
return ter; // LCOV_EXCL_LINE
(*mptoken)[sfAccount] = account;
(*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
(*mptoken)[sfFlags] = 0;
view.insert(mptoken);
ctx.view.insert(mptoken);
// Update owner count.
adjustOwnerCount(view, sleAcct, sponsorSle, 1, journal);
adjustOwnerCount(ctx.view, sleAcct, sponsorSle, 1, journal);
addSponsorToLedgerEntry(mptoken, sponsorSle);
return tesSUCCESS;
}
auto const sleMptIssuance = view.read(keylet::mptIssuance(mptIssuanceID));
auto const sleMptIssuance = ctx.view.read(keylet::mptIssuance(mptIssuanceID));
if (!sleMptIssuance)
return tecINTERNAL; // LCOV_EXCL_LINE
@@ -257,7 +254,7 @@ authorizeMPToken(
if (account != (*sleMptIssuance)[sfIssuer])
return tecINTERNAL; // LCOV_EXCL_LINE
auto const sleMpt = view.peek(keylet::mptoken(mptIssuanceID, *holderID));
auto const sleMpt = ctx.view.peek(keylet::mptoken(mptIssuanceID, *holderID));
if (!sleMpt)
return tecINTERNAL; // LCOV_EXCL_LINE
@@ -280,7 +277,7 @@ authorizeMPToken(
if (flagsIn != flagsOut)
sleMpt->setFieldU32(sfFlags, flagsOut);
view.update(sleMpt);
ctx.view.update(sleMpt);
return tesSUCCESS;
}
@@ -296,8 +293,7 @@ removeEmptyHolding(
// a token does exist, it will get deleted. If not, return success.
bool const accountIsIssuer = accountID == mptIssue.getIssuer();
auto const& mptID = mptIssue.getMptID();
auto& view = ctx.view;
auto const mptoken = view.peek(keylet::mptoken(mptID, accountID));
auto const mptoken = ctx.view.peek(keylet::mptoken(mptID, accountID));
if (!mptoken)
return accountIsIssuer ? (TER)tesSUCCESS : (TER)tecOBJECT_NOT_FOUND;
// Unlike a trust line, if the account is the issuer, and the token has a
@@ -305,7 +301,7 @@ removeEmptyHolding(
// accounting out of balance, so fail. Since this should be impossible
// anyway, I'm not going to put any effort into it.
if (mptoken->at(sfMPTAmount) != 0 ||
(view.rules().enabled(fixCleanup3_1_3) && (*mptoken)[~sfLockedAmount].valueOr(0) != 0))
(ctx.view.rules().enabled(fixCleanup3_1_3) && (*mptoken)[~sfLockedAmount].valueOr(0) != 0))
return tecHAS_OBLIGATIONS;
return authorizeMPToken(
@@ -424,8 +420,7 @@ enforceMPTokenAuthorization(
XRPAmount const& priorBalance, // for MPToken authorization
beast::Journal j)
{
auto& view = ctx.view;
auto const sleIssuance = view.read(keylet::mptIssuance(mptIssuanceID));
auto const sleIssuance = ctx.view.read(keylet::mptIssuance(mptIssuanceID));
if (!sleIssuance)
return tefINTERNAL; // LCOV_EXCL_LINE
@@ -437,7 +432,7 @@ enforceMPTokenAuthorization(
return tefINTERNAL; // LCOV_EXCL_LINE
auto const keylet = keylet::mptoken(mptIssuanceID, account);
auto const sleToken = view.read(keylet); // NOTE: might be null
auto const sleToken = ctx.view.read(keylet); // NOTE: might be null
auto const maybeDomainID = sleIssuance->at(~sfDomainID);
bool expired = false;
bool const authorizedByDomain = [&]() -> bool {
@@ -445,7 +440,7 @@ enforceMPTokenAuthorization(
if (!maybeDomainID.has_value())
return false; // LCOV_EXCL_LINE
auto const ter = verifyValidDomain(view, account, *maybeDomainID, j);
auto const ter = verifyValidDomain(ctx.view, account, *maybeDomainID, j);
if (isTesSuccess(ter))
return true;
if (ter == tecEXPIRED)

View File

@@ -639,35 +639,33 @@ addEmptyHolding(
Issue const& issue,
beast::Journal journal)
{
auto& view = ctx.view;
auto const tx = ctx.tx;
// Every account can hold XRP. An issuer can issue directly.
if (issue.native() || accountID == issue.getIssuer())
return tesSUCCESS;
auto const& issuerId = issue.getIssuer();
auto const& currency = issue.currency;
if (isGlobalFrozen(view, issuerId))
if (isGlobalFrozen(ctx.view, issuerId))
return tecFROZEN; // LCOV_EXCL_LINE
auto const& srcId = issuerId;
auto const& dstId = accountID;
auto const high = srcId > dstId;
auto const index = keylet::line(srcId, dstId, currency);
auto const sleSrc = view.peek(keylet::account(srcId));
auto const sleDst = view.peek(keylet::account(dstId));
auto const sleSrc = ctx.view.peek(keylet::account(srcId));
auto const sleDst = ctx.view.peek(keylet::account(dstId));
if (!sleDst || !sleSrc)
return tefINTERNAL; // LCOV_EXCL_LINE
if (!sleSrc->isFlag(lsfDefaultRipple))
return tecINTERNAL; // LCOV_EXCL_LINE
// If the line already exists, don't create it again.
if (view.read(index))
if (ctx.view.read(index))
return tecDUPLICATE;
SLE::pointer sponsorSle;
// A reserve sponsor only covers tx.Account's own objects.
if (!isPseudoAccount(sleDst) && accountID == tx[sfAccount])
if (!isPseudoAccount(sleDst) && accountID == ctx.tx[sfAccount])
{
auto sle = getTxReserveSponsor(ctx);
if (!sle)
@@ -676,13 +674,13 @@ addEmptyHolding(
}
// Can the account cover the trust line reserve ?
if (auto const ret =
checkInsufficientReserve(view, tx, sleDst, priorBalance, sponsorSle, 1, 0, journal);
if (auto const ret = checkInsufficientReserve(
ctx.view, ctx.tx, sleDst, priorBalance, sponsorSle, 1, 0, journal);
!isTesSuccess(ret))
return tecNO_LINE_INSUF_RESERVE;
return trustCreate(
view,
ctx.view,
high,
srcId,
dstId,
@@ -707,10 +705,9 @@ removeEmptyHolding(
Issue const& issue,
beast::Journal journal)
{
auto& view = ctx.view;
if (issue.native())
{
auto const sle = view.read(keylet::account(accountID));
auto const sle = ctx.view.read(keylet::account(accountID));
if (!sle)
return tecINTERNAL; // LCOV_EXCL_LINE
@@ -725,7 +722,7 @@ removeEmptyHolding(
// If the account is the issuer, then no line should exist. Check anyway.
// If a line does exist, it will get deleted. If not, return success.
bool const accountIsIssuer = accountID == issue.account;
auto const line = view.peek(keylet::line(accountID, issue));
auto const line = ctx.view.peek(keylet::line(accountID, issue));
if (!line)
return accountIsIssuer ? (TER)tesSUCCESS : (TER)tecOBJECT_NOT_FOUND;
if (!accountIsIssuer && line->at(sfBalance)->iou() != beast::kZero)
@@ -735,13 +732,13 @@ removeEmptyHolding(
if (line->isFlag(lsfLowReserve))
{
// Clear reserve for low account.
auto sleLowAccount = view.peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
auto sleLowAccount = ctx.view.peek(keylet::account(line->at(sfLowLimit)->getIssuer()));
if (!sleLowAccount)
return tecINTERNAL; // LCOV_EXCL_LINE
auto const currentLowSponsor = getLedgerEntryReserveSponsor(view, line, sfLowSponsor);
auto const currentLowSponsor = getLedgerEntryReserveSponsor(ctx.view, line, sfLowSponsor);
adjustOwnerCount(view, sleLowAccount, currentLowSponsor, -1, journal);
adjustOwnerCount(ctx.view, sleLowAccount, currentLowSponsor, -1, journal);
// It's not really necessary to clear the reserve flag, since the line
// is about to be deleted, but this will make the metadata reflect an
// accurate state at the time of deletion.
@@ -752,13 +749,13 @@ removeEmptyHolding(
if (line->isFlag(lsfHighReserve))
{
// Clear reserve for high account.
auto sleHighAccount = view.peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
auto sleHighAccount = ctx.view.peek(keylet::account(line->at(sfHighLimit)->getIssuer()));
if (!sleHighAccount)
return tecINTERNAL; // LCOV_EXCL_LINE
auto const currentHighSponsor = getLedgerEntryReserveSponsor(view, line, sfHighSponsor);
auto const currentHighSponsor = getLedgerEntryReserveSponsor(ctx.view, line, sfHighSponsor);
adjustOwnerCount(view, sleHighAccount, currentHighSponsor, -1, journal);
adjustOwnerCount(ctx.view, sleHighAccount, currentHighSponsor, -1, journal);
// It's not really necessary to clear the reserve flag, since the line
// is about to be deleted, but this will make the metadata reflect an
// accurate state at the time of deletion.
@@ -767,7 +764,11 @@ removeEmptyHolding(
}
return trustDelete(
view, line, line->at(sfLowLimit)->getIssuer(), line->at(sfHighLimit)->getIssuer(), journal);
ctx.view,
line,
line->at(sfLowLimit)->getIssuer(),
line->at(sfHighLimit)->getIssuer(),
journal);
}
TER

View File

@@ -108,8 +108,7 @@ MPTokenIssuanceCreate::create(
beast::Journal journal,
MPTCreateArgs const& args)
{
auto& view = ctx.view;
auto const acct = view.peek(keylet::account(args.account));
auto const acct = ctx.view.peek(keylet::account(args.account));
if (!acct)
return std::unexpected(tecINTERNAL); // LCOV_EXCL_LINE
@@ -125,7 +124,7 @@ MPTokenIssuanceCreate::create(
if (args.priorBalance)
{
if (auto const ret = checkInsufficientReserve(
view, ctx.tx, acct, *(args.priorBalance), sponsorSle, 1, 0, journal);
ctx.view, ctx.tx, acct, *(args.priorBalance), sponsorSle, 1, 0, journal);
!isTesSuccess(ret))
return std::unexpected(ret); // tecINSUFFICIENT_RESERVE
}
@@ -135,7 +134,7 @@ MPTokenIssuanceCreate::create(
// create the MPTokenIssuance
{
auto const ownerNode = view.dirInsert(
auto const ownerNode = ctx.view.dirInsert(
keylet::ownerDir(args.account), mptIssuanceKeylet, describeOwnerDir(args.account));
if (!ownerNode)
@@ -173,7 +172,7 @@ MPTokenIssuanceCreate::create(
// populate this after the pseudo-account's MPToken /
// RippleState has been installed. A missing holding here
// would dangle the pointer and is a programmer error.
auto const sleHolding = view.read(keylet::unchecked(*args.referenceHolding));
auto const sleHolding = ctx.view.read(keylet::unchecked(*args.referenceHolding));
if (!sleHolding)
return std::unexpected(tecINTERNAL); // LCOV_EXCL_LINE
auto const type = sleHolding->getType();
@@ -184,11 +183,11 @@ MPTokenIssuanceCreate::create(
addSponsorToLedgerEntry(mptIssuance, sponsorSle);
view.insert(mptIssuance);
ctx.view.insert(mptIssuance);
}
// Update owner count.
adjustOwnerCount(view, acct, sponsorSle, 1, journal);
adjustOwnerCount(ctx.view, acct, sponsorSle, 1, journal);
return mptId;
}