mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-23 07:00:21 +00:00
migrate createMPToken, reduce diff
This commit is contained in:
@@ -125,8 +125,7 @@ ownerCount(SLE::const_ref sle, beast::Journal j, std::int32_t ownerCountAdj = 0)
|
||||
* and the sponsor's sponsoring count.
|
||||
*
|
||||
* @param view The apply view for making changes
|
||||
* @param accountSle The account's ledger entry
|
||||
* @param sponsorSle The sponsor's ledger entry (if applicable)
|
||||
* @param reserveCtx The account and sponsor information
|
||||
* @param count Amount to add to the owner count
|
||||
* @param j Journal for logging
|
||||
*/
|
||||
@@ -145,8 +144,7 @@ increaseOwnerCount(
|
||||
* sfSponsor field.
|
||||
*
|
||||
* @param view The apply view for making changes
|
||||
* @param accountSle The account's ledger entry
|
||||
* @param sponsorSle The sponsor's ledger entry (if applicable)
|
||||
* @param reserveCtx The account and sponsor information
|
||||
* @param count Amount to remove from the owner count
|
||||
* @param j Journal for logging
|
||||
*/
|
||||
@@ -157,19 +155,23 @@ decreaseOwnerCount(
|
||||
std::uint32_t count,
|
||||
beast::Journal j);
|
||||
|
||||
/** Decrease the owner counters of the account. If the object has a sponsor,
|
||||
* adjust its counters too. Used primarily just before deleting the object.
|
||||
/** Decrease owner-count fields for an existing ledger object.
|
||||
*
|
||||
* This helper derives the reserve sponsor from objectSle's sfSponsor field,
|
||||
* then updates the same owner-count fields as decreaseOwnerCount. Use this
|
||||
* when removing an existing object whose reserve sponsor is stored on that
|
||||
* object.
|
||||
*
|
||||
* @param view The apply view for making changes
|
||||
* @param ownerSle The account's ledger entry
|
||||
* @param accountSle The account's ledger entry
|
||||
* @param objectSle The object's ledger entry
|
||||
* @param count Positive amount to remove from the owner count
|
||||
* @param j Journal for logging (default: null sink)
|
||||
* @param count Amount to remove from the owner count
|
||||
* @param j Journal for logging
|
||||
*/
|
||||
void
|
||||
decreaseOwnerCountForObject(
|
||||
ApplyView& view,
|
||||
SLE::pointer ownerSle,
|
||||
SLE::ref accountSle,
|
||||
SLE::ref objectSle,
|
||||
std::uint32_t count,
|
||||
beast::Journal j);
|
||||
|
||||
@@ -196,24 +196,21 @@ escrowUnlockApplyHelper<MPTIssue>(
|
||||
auto const mptKeylet = keylet::mptoken(issuanceKey.key, receiver);
|
||||
if (!ctx.view.exists(mptKeylet) && createAsset && !receiverIssuer)
|
||||
{
|
||||
auto const sponsorSle = ctx.txReserveContext.sponsorSle;
|
||||
|
||||
if (auto const ret =
|
||||
checkInsufficientReserve(ctx, sleDest, xrpBalance, {.ownerCountDelta = 1}, journal);
|
||||
!isTesSuccess(ret))
|
||||
return ret;
|
||||
|
||||
if (auto const ter = createMPToken(ctx.view, mptID, receiver, sponsorSle, 0);
|
||||
!isTesSuccess(ter))
|
||||
auto const reserveCtx =
|
||||
ReserveContext::makeFromAccount(ctx.view, sleDest, ctx.txReserveContext.sponsorSle);
|
||||
|
||||
if (auto const ter = createMPToken(ctx.view, mptID, reserveCtx, 0); !isTesSuccess(ter))
|
||||
{
|
||||
return ter; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
// update owner count.
|
||||
increaseOwnerCount(
|
||||
ctx.view, ReserveContext::makeFromAccount(ctx.view, sleDest, sponsorSle), 1, journal);
|
||||
auto mptSle = ctx.view.peek(mptKeylet);
|
||||
addSponsorToLedgerEntry(mptSle, sponsorSle);
|
||||
increaseOwnerCount(ctx.view, reserveCtx, 1, journal);
|
||||
}
|
||||
|
||||
if (!ctx.view.exists(mptKeylet) && !receiverIssuer)
|
||||
|
||||
@@ -242,8 +242,7 @@ TER
|
||||
createMPToken(
|
||||
ApplyView& view,
|
||||
MPTID const& mptIssuanceID,
|
||||
AccountID const& account,
|
||||
SLE::ref sponsorSle,
|
||||
ReserveContext const& reserveCtx,
|
||||
std::uint32_t const flags);
|
||||
|
||||
TER
|
||||
|
||||
@@ -296,7 +296,7 @@ decreaseOwnerCount(
|
||||
void
|
||||
decreaseOwnerCountForObject(
|
||||
ApplyView& view,
|
||||
SLE::pointer ownerSle,
|
||||
SLE::ref ownerSle,
|
||||
SLE::ref objectSle,
|
||||
std::uint32_t count,
|
||||
beast::Journal j)
|
||||
|
||||
@@ -925,10 +925,10 @@ TER
|
||||
createMPToken(
|
||||
ApplyView& view,
|
||||
MPTID const& mptIssuanceID,
|
||||
AccountID const& account,
|
||||
SLE::ref sponsorSle,
|
||||
ReserveContext const& reserveCtx,
|
||||
std::uint32_t const flags)
|
||||
{
|
||||
auto const account = reserveCtx.accountID();
|
||||
auto const mptokenKey = keylet::mptoken(mptIssuanceID, account);
|
||||
|
||||
auto const ownerNode =
|
||||
@@ -943,8 +943,7 @@ createMPToken(
|
||||
(*mptoken)[sfFlags] = flags;
|
||||
(*mptoken)[sfOwnerNode] = *ownerNode;
|
||||
|
||||
if (sponsorSle)
|
||||
addSponsorToLedgerEntry(mptoken, sponsorSle);
|
||||
addSponsorToLedgerEntry(mptoken, reserveCtx.sponsorSle);
|
||||
|
||||
view.insert(mptoken);
|
||||
|
||||
@@ -969,8 +968,7 @@ checkCreateMPT(
|
||||
auto const mptokenID = keylet::mptoken(mptIssuanceID.key, holder);
|
||||
if (!view.exists(mptokenID))
|
||||
{
|
||||
if (auto const err =
|
||||
createMPToken(view, mptIssue.getMptID(), holder, reserveCtx.sponsorSle, 0);
|
||||
if (auto const err = createMPToken(view, mptIssue.getMptID(), reserveCtx, 0);
|
||||
!isTesSuccess(err))
|
||||
{
|
||||
return err;
|
||||
|
||||
@@ -424,10 +424,10 @@ removeToken(ApplyView& view, AccountID const& owner, uint256 const& nftokenID, S
|
||||
|
||||
if (cnt != 0)
|
||||
{
|
||||
increaseOwnerCount(
|
||||
decreaseOwnerCount(
|
||||
view,
|
||||
ReserveContext::makeFromAccount(view, view.peek(keylet::account(owner)), nullptr),
|
||||
-1 * static_cast<std::int32_t>(cnt),
|
||||
cnt,
|
||||
beast::Journal{beast::Journal::getNullSink()});
|
||||
}
|
||||
|
||||
@@ -463,10 +463,10 @@ removeToken(ApplyView& view, AccountID const& owner, uint256 const& nftokenID, S
|
||||
curr->makeFieldAbsent(sfPreviousPageMin);
|
||||
}
|
||||
|
||||
increaseOwnerCount(
|
||||
decreaseOwnerCount(
|
||||
view,
|
||||
ReserveContext::makeFromAccount(view, view.peek(keylet::account(owner)), nullptr),
|
||||
-1,
|
||||
1,
|
||||
beast::Journal{beast::Journal::getNullSink()});
|
||||
|
||||
view.update(curr);
|
||||
@@ -522,10 +522,10 @@ removeToken(ApplyView& view, AccountID const& owner, uint256 const& nftokenID, S
|
||||
view.peek(Keylet(ltNFTOKEN_PAGE, next->key()))))
|
||||
cnt++;
|
||||
|
||||
increaseOwnerCount(
|
||||
decreaseOwnerCount(
|
||||
view,
|
||||
ReserveContext::makeFromAccount(view, view.peek(keylet::account(owner)), nullptr),
|
||||
-1 * static_cast<std::int32_t>(cnt),
|
||||
cnt,
|
||||
beast::Journal{beast::Journal::getNullSink()});
|
||||
|
||||
return tesSUCCESS;
|
||||
@@ -642,10 +642,10 @@ deleteTokenOffer(ApplyView& view, SLE::ref offer)
|
||||
false))
|
||||
return false;
|
||||
|
||||
increaseOwnerCount(
|
||||
decreaseOwnerCount(
|
||||
view,
|
||||
ReserveContext::makeFromAccount(view, view.peek(keylet::account(owner)), nullptr),
|
||||
-1,
|
||||
1,
|
||||
beast::Journal{beast::Journal::getNullSink()});
|
||||
|
||||
view.erase(offer);
|
||||
|
||||
@@ -378,7 +378,7 @@ updateTrustLine(
|
||||
// Clear the reserve of the sender, possibly delete the line!
|
||||
auto const currentSponsor =
|
||||
getLedgerEntryReserveSponsor(view, state, !bSenderHigh ? sfLowSponsor : sfHighSponsor);
|
||||
increaseOwnerCount(view, ReserveContext::makeFromAccount(view, sle, currentSponsor), -1, j);
|
||||
decreaseOwnerCount(view, ReserveContext::makeFromAccount(view, sle, currentSponsor), 1, j);
|
||||
|
||||
// Clear reserve flag.
|
||||
state->clearFlag(senderReserveFlag);
|
||||
@@ -725,10 +725,10 @@ removeEmptyHolding(
|
||||
|
||||
auto const currentLowSponsor = getLedgerEntryReserveSponsor(ctx.view, line, sfLowSponsor);
|
||||
|
||||
increaseOwnerCount(
|
||||
decreaseOwnerCount(
|
||||
ctx.view,
|
||||
ReserveContext::makeFromAccount(ctx.view, sleLowAccount, currentLowSponsor),
|
||||
-1,
|
||||
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
|
||||
@@ -746,10 +746,10 @@ removeEmptyHolding(
|
||||
|
||||
auto const currentHighSponsor = getLedgerEntryReserveSponsor(ctx.view, line, sfHighSponsor);
|
||||
|
||||
increaseOwnerCount(
|
||||
decreaseOwnerCount(
|
||||
ctx.view,
|
||||
ReserveContext::makeFromAccount(ctx.view, sleHighAccount, currentHighSponsor),
|
||||
-1,
|
||||
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
|
||||
@@ -812,8 +812,8 @@ deleteAMMTrustLine(
|
||||
if (!sleState->isFlag(uFlags))
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
increaseOwnerCount(
|
||||
view, ReserveContext::makeFromAccount(view, !ammLow ? sleLow : sleHigh, sponsorSle), -1, j);
|
||||
decreaseOwnerCount(
|
||||
view, ReserveContext::makeFromAccount(view, !ammLow ? sleLow : sleHigh, sponsorSle), 1, j);
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
@@ -725,8 +725,8 @@ directSendNoFeeIOU(
|
||||
auto const senderSle = view.peek(keylet::account(uSenderID));
|
||||
if (!senderSle)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
increaseOwnerCount(
|
||||
view, ReserveContext::makeFromAccount(view, senderSle, currentSponsor), -1, j);
|
||||
decreaseOwnerCount(
|
||||
view, ReserveContext::makeFromAccount(view, senderSle, currentSponsor), 1, j);
|
||||
|
||||
removeSponsorFromLedgerEntry(
|
||||
sleRippleState, !bSenderHigh ? sfLowSponsor : sfHighSponsor);
|
||||
|
||||
@@ -204,6 +204,7 @@ SponsorshipSet::doApply()
|
||||
auto const feeAmount = ctx_.tx[~sfFeeAmount];
|
||||
auto const maxFee = ctx_.tx[~sfMaxFee];
|
||||
auto const remainingOwnerCount = ctx_.tx[~sfRemainingOwnerCount];
|
||||
|
||||
bool const hasPositiveFeeAmount = feeAmount.has_value() && *feeAmount > beast::kZero;
|
||||
|
||||
auto const applyViewContext = ctx_.getApplyViewContext();
|
||||
|
||||
@@ -727,8 +727,8 @@ finalizeClaimHelper(
|
||||
// Remove the claim id from the ledger
|
||||
outerSb.erase(sleClaimID);
|
||||
|
||||
increaseOwnerCount(
|
||||
outerSb, ReserveContext::makeFromAccount(outerSb, sleOwner, nullptr), -1, j);
|
||||
decreaseOwnerCount(
|
||||
outerSb, ReserveContext::makeFromAccount(outerSb, sleOwner, nullptr), 1, j);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -591,11 +591,7 @@ CheckCash::doApply()
|
||||
}
|
||||
|
||||
// If we succeeded, update the check owner's reserve.
|
||||
increaseOwnerCount(
|
||||
psb,
|
||||
ReserveContext::makeFromAccount(psb, psb.peek(keylet::account(srcId)), sponsorCheckSle),
|
||||
-1,
|
||||
viewJ);
|
||||
decreaseOwnerCountForObject(psb, psb.peek(keylet::account(srcId)), sleCheck, 1, viewJ);
|
||||
|
||||
// Remove check from ledger.
|
||||
psb.erase(sleCheck);
|
||||
|
||||
@@ -116,7 +116,7 @@ CredentialAccept::doApply()
|
||||
sleCred->setFieldU32(sfFlags, lsfAccepted);
|
||||
view().update(sleCred);
|
||||
|
||||
increaseOwnerCount(view(), ReserveContext::makeFromAccount(view(), sleIssuer, nullptr), -1, j_);
|
||||
decreaseOwnerCount(view(), ReserveContext::makeFromAccount(view(), sleIssuer, nullptr), 1, j_);
|
||||
increaseOwnerCount(view(), ReserveContext::makeFromAccount(view(), sleSubject, nullptr), 1, j_);
|
||||
|
||||
return tesSUCCESS;
|
||||
|
||||
@@ -332,7 +332,9 @@ applyCreate(ApplyContext& ctx, Sandbox& sb, AccountID const& account, beast::Jou
|
||||
return err;
|
||||
}
|
||||
|
||||
if (auto const err = createMPToken(sb, mptID, accountId, {}, flags);
|
||||
// AMM is a pseudo-account, so it is never reserve-sponsored.
|
||||
if (auto const err = createMPToken(
|
||||
sb, mptID, ReserveContext::makeFromAccount(sb, acc, nullptr), flags);
|
||||
!isTesSuccess(err))
|
||||
return err;
|
||||
// Don't adjust AMM owner count.
|
||||
|
||||
@@ -50,7 +50,7 @@ DIDDelete::deleteSLE(ApplyView& view, SLE::pointer sle, AccountID const owner, b
|
||||
if (!sleOwner)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
increaseOwnerCount(view, ReserveContext::makeFromAccount(view, sleOwner, nullptr), -1, j);
|
||||
decreaseOwnerCount(view, ReserveContext::makeFromAccount(view, sleOwner, nullptr), 1, j);
|
||||
view.update(sleOwner);
|
||||
|
||||
// Remove object from ledger
|
||||
|
||||
@@ -460,12 +460,11 @@ EscrowCreate::doApply()
|
||||
// - sponsored: adj=0 — sponsor covers the new owner increment,
|
||||
// so the source only owes its base reserve.
|
||||
// - unsponsored: adj=1 — source owes base + the new increment.
|
||||
std::int32_t const ownerCountAdj = sponsorSle ? 0 : 1;
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx_.getApplyViewContext(),
|
||||
sle,
|
||||
balance - STAmount(amount).xrp(),
|
||||
{.ownerCountDelta = ownerCountAdj},
|
||||
{.ownerCountDelta = sponsorSle ? 0 : 1},
|
||||
j_);
|
||||
!isTesSuccess(ret))
|
||||
return tecUNFUNDED;
|
||||
|
||||
@@ -197,7 +197,7 @@ LoanBrokerDelete::doApply()
|
||||
// Decreases the owner count by two: one for the LoanBroker object, and
|
||||
// one for the pseudo-account.
|
||||
// LoanBroker object can be sponsored
|
||||
increaseOwnerCount(view(), ReserveContext::makeFromAccount(view(), owner, nullptr), -2, j_);
|
||||
decreaseOwnerCount(view(), ReserveContext::makeFromAccount(view(), owner, nullptr), 2, j_);
|
||||
}
|
||||
|
||||
associateAsset(*broker, vaultAsset);
|
||||
|
||||
@@ -110,7 +110,7 @@ LoanDelete::doApply()
|
||||
// Decrement the LoanBroker's owner count.
|
||||
// The broker's owner count is solely for the number of outstanding loans,
|
||||
// and is distinct from the broker's pseudo-account's owner count
|
||||
increaseOwnerCount(view, ReserveContext::makeFromAccount(view, brokerSle, nullptr), -1, j_);
|
||||
decreaseOwnerCount(view, ReserveContext::makeFromAccount(view, brokerSle, nullptr), 1, j_);
|
||||
|
||||
// If there are no loans left, then any remaining debt must be forgiven,
|
||||
// because there is no other way to pay it back.
|
||||
@@ -131,7 +131,7 @@ LoanDelete::doApply()
|
||||
}
|
||||
}
|
||||
// Decrement the borrower's owner count
|
||||
increaseOwnerCount(view, ReserveContext::makeFromAccount(view, borrowerSle, nullptr), -1, j_);
|
||||
decreaseOwnerCount(view, ReserveContext::makeFromAccount(view, borrowerSle, nullptr), 1, j_);
|
||||
|
||||
// These associations shouldn't do anything, but do them just to be safe
|
||||
associateAsset(*loanSle, vaultAsset);
|
||||
|
||||
@@ -70,8 +70,8 @@ OracleDelete::deleteOracle(
|
||||
if (!sleOwner)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
auto const count = sle->getFieldArray(sfPriceDataSeries).size() > 5 ? -2 : -1;
|
||||
increaseOwnerCount(view, ReserveContext::makeFromAccount(view, sleOwner, nullptr), count, j);
|
||||
std::uint32_t const count = sle->getFieldArray(sfPriceDataSeries).size() > 5 ? 2 : 1;
|
||||
decreaseOwnerCount(view, ReserveContext::makeFromAccount(view, sleOwner, nullptr), count, j);
|
||||
view.erase(sle);
|
||||
|
||||
return tesSUCCESS;
|
||||
|
||||
@@ -186,11 +186,20 @@ adjustOracleOwnerCount(ApplyContext& ctx, int count)
|
||||
{
|
||||
if (auto const sleAccount = ctx.view().peek(keylet::account(ctx.tx[sfAccount])))
|
||||
{
|
||||
increaseOwnerCount(
|
||||
ctx.view(),
|
||||
ReserveContext::makeFromAccount(ctx.view(), sleAccount, nullptr),
|
||||
count,
|
||||
ctx.journal);
|
||||
auto reserveCtx = ctx.getApplyViewContext().txReserveContext;
|
||||
XRPL_ASSERT(
|
||||
!reserveCtx.isSponsored(),
|
||||
"OracleSet::adjustOracleOwnerCount : OracleSet is not reserve-sponsored");
|
||||
if (count > 0)
|
||||
{
|
||||
increaseOwnerCount(
|
||||
ctx.view(), reserveCtx, static_cast<std::uint32_t>(count), ctx.journal);
|
||||
}
|
||||
else if (count < 0)
|
||||
{
|
||||
decreaseOwnerCount(
|
||||
ctx.view(), reserveCtx, static_cast<std::uint32_t>(-count), ctx.journal);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,8 @@ PermissionedDomainDelete::doApply()
|
||||
XRPL_ASSERT(
|
||||
ownerSle && ownerSle->getFieldU32(sfOwnerCount) > 0,
|
||||
"xrpl::PermissionedDomainDelete::doApply : nonzero owner count");
|
||||
increaseOwnerCount(
|
||||
view(), ReserveContext::makeFromAccount(view(), ownerSle, nullptr), -1, ctx_.journal);
|
||||
decreaseOwnerCount(
|
||||
view(), ReserveContext::makeFromAccount(view(), ownerSle, nullptr), 1, ctx_.journal);
|
||||
view().erase(slePd);
|
||||
|
||||
return tesSUCCESS;
|
||||
|
||||
@@ -562,10 +562,10 @@ TrustSet::doApply()
|
||||
if (bLowReserveClear && bLowReserved)
|
||||
{
|
||||
// Clear reserve for low account.
|
||||
increaseOwnerCount(
|
||||
decreaseOwnerCount(
|
||||
view(),
|
||||
ReserveContext::makeFromAccount(view(), sleLowAccount, currentLowSponsor),
|
||||
-1,
|
||||
1,
|
||||
viewJ);
|
||||
uFlagsOut &= ~lsfLowReserve;
|
||||
|
||||
@@ -603,10 +603,10 @@ TrustSet::doApply()
|
||||
if (bHighReserveClear && bHighReserved)
|
||||
{
|
||||
// Clear reserve for high account.
|
||||
increaseOwnerCount(
|
||||
decreaseOwnerCount(
|
||||
view(),
|
||||
ReserveContext::makeFromAccount(view(), sleHighAccount, currentHighSponsor),
|
||||
-1,
|
||||
1,
|
||||
viewJ);
|
||||
uFlagsOut &= ~lsfHighReserve;
|
||||
|
||||
@@ -679,8 +679,7 @@ TrustSet::doApply()
|
||||
|
||||
JLOG(j_.trace()) << "doTrustSet: Creating ripple line: " << to_string(k.key);
|
||||
|
||||
// Create a new ripple line. The ApplyViewContext overload derives the
|
||||
// sponsor (XLS-68: only when the reserved account is the tx.Account).
|
||||
// Create a new ripple line.
|
||||
terResult = trustCreate(
|
||||
applyViewContext,
|
||||
bHigh,
|
||||
|
||||
@@ -155,8 +155,7 @@ VaultDelete::doApply()
|
||||
return tefBAD_LEDGER;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
increaseOwnerCount(
|
||||
view(), ReserveContext::makeFromAccount(view(), pseudoAcct, nullptr), -1, j_);
|
||||
decreaseOwnerCount(view(), ReserveContext::makeFromAccount(view(), pseudoAcct, nullptr), 1, j_);
|
||||
|
||||
view().erase(mpt);
|
||||
|
||||
@@ -215,7 +214,7 @@ VaultDelete::doApply()
|
||||
}
|
||||
|
||||
// We are destroying Vault and PseudoAccount, hence decrease by 2
|
||||
increaseOwnerCount(view(), ReserveContext::makeFromAccount(view(), owner, nullptr), -2, j_);
|
||||
decreaseOwnerCount(view(), ReserveContext::makeFromAccount(view(), owner, nullptr), 2, j_);
|
||||
|
||||
// Destroy the vault.
|
||||
view().erase(vault);
|
||||
|
||||
Reference in New Issue
Block a user