mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-04 01:06:48 +00:00
address revew (std::optional + std::shared_ptr<SLE>)
This commit is contained in:
@@ -565,40 +565,40 @@ checkInsufficientReserve(
|
||||
STTx const& tx,
|
||||
std::shared_ptr<SLE const> accSle,
|
||||
STAmount const& accBalance,
|
||||
std::optional<std::shared_ptr<SLE const>> const& sponsorSle,
|
||||
std::shared_ptr<SLE const> const& sponsorSle,
|
||||
std::int32_t ownerCountDelta,
|
||||
std::int32_t accountCountDelta = 0);
|
||||
|
||||
std::optional<AccountID>
|
||||
getTxReserveSponsorAccountID(STTx const& tx);
|
||||
|
||||
std::optional<std::shared_ptr<SLE>>
|
||||
std::shared_ptr<SLE>
|
||||
getTxReserveSponsor(ApplyView& view, STTx const& tx);
|
||||
|
||||
std::optional<std::shared_ptr<SLE const>>
|
||||
std::shared_ptr<SLE const> const
|
||||
getTxReserveSponsor(ReadView const& view, STTx const& tx);
|
||||
|
||||
std::optional<AccountID>
|
||||
getLedgerEntryReserveSponsorAccountID(
|
||||
std::shared_ptr<SLE const> sle,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsorAccount);
|
||||
|
||||
std::optional<std::shared_ptr<SLE>>
|
||||
std::shared_ptr<SLE>
|
||||
getLedgerEntryReserveSponsor(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> sle,
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsorAccount);
|
||||
|
||||
std::optional<std::shared_ptr<SLE const>>
|
||||
std::shared_ptr<SLE const> const
|
||||
getLedgerEntryReserveSponsor(
|
||||
ReadView const& view,
|
||||
std::shared_ptr<SLE const> sle,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field = sfSponsorAccount);
|
||||
|
||||
void
|
||||
addSponsorToLedgerEntry(
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
std::optional<std::shared_ptr<SLE>> const& sponsorSle,
|
||||
std::shared_ptr<SLE> const& sponsorSle,
|
||||
SF_ACCOUNT const& field = sfSponsorAccount);
|
||||
|
||||
void
|
||||
@@ -617,7 +617,7 @@ void
|
||||
adjustOwnerCount(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> const& accountSle,
|
||||
std::optional<std::shared_ptr<SLE>> const& sponsorSle,
|
||||
std::shared_ptr<SLE> const& sponsorSle,
|
||||
std::int32_t amount,
|
||||
beast::Journal j);
|
||||
|
||||
@@ -626,7 +626,7 @@ adjustOwnerCount(
|
||||
ApplyView& view,
|
||||
STTx const& tx,
|
||||
std::shared_ptr<SLE> const& accountSle,
|
||||
std::optional<std::shared_ptr<SLE>> const& sponsorSle,
|
||||
std::shared_ptr<SLE> const& sponsorSle,
|
||||
std::int32_t amount,
|
||||
beast::Journal j)
|
||||
{
|
||||
@@ -646,8 +646,7 @@ adjustOwnerCount(
|
||||
view,
|
||||
tx,
|
||||
view.peek(keylet::account(account)),
|
||||
sponsor ? view.peek(keylet::account(*sponsor))
|
||||
: std::optional<std::shared_ptr<SLE>>(),
|
||||
sponsor ? view.peek(keylet::account(*sponsor)) : std::shared_ptr<SLE>(),
|
||||
amount,
|
||||
j);
|
||||
}
|
||||
|
||||
@@ -1167,7 +1167,7 @@ checkInsufficientReserve(
|
||||
STTx const& tx,
|
||||
std::shared_ptr<SLE const> accSle,
|
||||
STAmount const& accBalance,
|
||||
std::optional<std::shared_ptr<SLE const>> const& sponsorSle,
|
||||
std::shared_ptr<SLE const> const& sponsorSle,
|
||||
std::int32_t ownerCountDelta,
|
||||
std::int32_t accountCountDelta)
|
||||
{
|
||||
@@ -1176,7 +1176,7 @@ checkInsufficientReserve(
|
||||
auto const isCoSigning = isSponsorReserveCoSigning(tx);
|
||||
|
||||
auto const sle = view.read(keylet::sponsor(
|
||||
(*sponsorSle)->getAccountID(sfAccount),
|
||||
sponsorSle->getAccountID(sfAccount),
|
||||
accSle->getAccountID(sfAccount)));
|
||||
|
||||
if (isCoSigning)
|
||||
@@ -1190,15 +1190,14 @@ checkInsufficientReserve(
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
auto const sponsorBalance =
|
||||
(*sponsorSle)->getFieldAmount(sfBalance);
|
||||
auto const sponsorBalance = sponsorSle->getFieldAmount(sfBalance);
|
||||
STAmount const sponsorReserve{view.fees().accountReserve(
|
||||
(*sponsorSle)->getFieldU32(sfOwnerCount),
|
||||
(*sponsorSle)->getFieldU32(sfSponsoredOwnerCount),
|
||||
(*sponsorSle)->getFieldU32(sfSponsoringOwnerCount) +
|
||||
sponsorSle->getFieldU32(sfOwnerCount),
|
||||
sponsorSle->getFieldU32(sfSponsoredOwnerCount),
|
||||
sponsorSle->getFieldU32(sfSponsoringOwnerCount) +
|
||||
ownerCountDelta,
|
||||
(*sponsorSle)->isFieldPresent(sfSponsorAccount),
|
||||
(*sponsorSle)->getFieldU32(sfSponsoringAccountCount) +
|
||||
sponsorSle->isFieldPresent(sfSponsorAccount),
|
||||
sponsorSle->getFieldU32(sfSponsoringAccountCount) +
|
||||
accountCountDelta)};
|
||||
|
||||
if (sponsorBalance < sponsorReserve)
|
||||
@@ -1239,65 +1238,65 @@ getTxReserveSponsorAccountID(STTx const& tx)
|
||||
if (sponsorObj.isFlag(tfSponsorReserve))
|
||||
return sponsorObj.getAccountID(sfAccount);
|
||||
}
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<SLE>>
|
||||
std::shared_ptr<SLE>
|
||||
getTxReserveSponsor(ApplyView& view, STTx const& tx)
|
||||
{
|
||||
auto const sponsorID = getTxReserveSponsorAccountID(tx);
|
||||
if (sponsorID)
|
||||
return view.peek(keylet::account(*sponsorID));
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<SLE const>>
|
||||
std::shared_ptr<SLE const> const
|
||||
getTxReserveSponsor(ReadView const& view, STTx const& tx)
|
||||
{
|
||||
auto const sponsorID = getTxReserveSponsorAccountID(tx);
|
||||
if (sponsorID)
|
||||
return view.read(keylet::account(*sponsorID));
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<AccountID>
|
||||
getLedgerEntryReserveSponsorAccountID(
|
||||
std::shared_ptr<SLE const> sle,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field)
|
||||
{
|
||||
if (sle->isFieldPresent(field))
|
||||
return sle->getAccountID(field);
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<SLE>>
|
||||
std::shared_ptr<SLE>
|
||||
getLedgerEntryReserveSponsor(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> sle,
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
SF_ACCOUNT const& field)
|
||||
{
|
||||
auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field);
|
||||
if (sponsorID)
|
||||
return view.peek(keylet::account(*sponsorID));
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<SLE const>>
|
||||
std::shared_ptr<SLE const> const
|
||||
getLedgerEntryReserveSponsor(
|
||||
ReadView const& view,
|
||||
std::shared_ptr<SLE const> sle,
|
||||
std::shared_ptr<SLE const> const& sle,
|
||||
SF_ACCOUNT const& field)
|
||||
{
|
||||
auto const sponsorID = getLedgerEntryReserveSponsorAccountID(sle, field);
|
||||
if (sponsorID)
|
||||
return view.read(keylet::account(*sponsorID));
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
void
|
||||
addSponsorToLedgerEntry(
|
||||
std::shared_ptr<SLE> const& sle,
|
||||
std::optional<std::shared_ptr<SLE>> const& sponsorSle,
|
||||
std::shared_ptr<SLE> const& sponsorSle,
|
||||
SF_ACCOUNT const& field)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
@@ -1306,7 +1305,7 @@ addSponsorToLedgerEntry(
|
||||
(sle->getType() != ltRIPPLE_STATE && field == sfSponsorAccount),
|
||||
"addSponsorToLedgerEntry : Invalid field to the LedgerEntry");
|
||||
if (sponsorSle)
|
||||
sle->setAccountID(field, (*sponsorSle)->getAccountID(sfAccount));
|
||||
sle->setAccountID(field, sponsorSle->getAccountID(sfAccount));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1333,7 +1332,7 @@ void
|
||||
adjustOwnerCount(
|
||||
ApplyView& view,
|
||||
std::shared_ptr<SLE> const& accountSle,
|
||||
std::optional<std::shared_ptr<SLE>> const& sponsorSle,
|
||||
std::shared_ptr<SLE> const& sponsorSle,
|
||||
std::int32_t amount,
|
||||
beast::Journal j)
|
||||
{
|
||||
@@ -1345,19 +1344,19 @@ adjustOwnerCount(
|
||||
{
|
||||
XRPL_ASSERT(sponsorSle, "xrpl::adjustOwnerCount : sponsor exists");
|
||||
auto const account = accountSle->getAccountID(sfAccount);
|
||||
auto const sponsorAcc = (*sponsorSle)->getAccountID(sfAccount);
|
||||
auto const sponsorAcc = (sponsorSle)->getAccountID(sfAccount);
|
||||
{
|
||||
// modify sponsor's SponsoringOwnerCount
|
||||
std::uint32_t const current{
|
||||
(*sponsorSle)->getFieldU32(sfSponsoringOwnerCount)};
|
||||
(sponsorSle)->getFieldU32(sfSponsoringOwnerCount)};
|
||||
std::uint32_t const adjusted =
|
||||
confineOwnerCount(current, amount, sponsorAcc, j);
|
||||
view.adjustOwnerCountHook(sponsorAcc, current, adjusted);
|
||||
if (adjusted == 0)
|
||||
(*sponsorSle)->makeFieldAbsent(sfSponsoringOwnerCount);
|
||||
(sponsorSle)->makeFieldAbsent(sfSponsoringOwnerCount);
|
||||
else
|
||||
(*sponsorSle)->setFieldU32(sfSponsoringOwnerCount, adjusted);
|
||||
view.update(*sponsorSle);
|
||||
(sponsorSle)->setFieldU32(sfSponsoringOwnerCount, adjusted);
|
||||
view.update(sponsorSle);
|
||||
}
|
||||
{
|
||||
// modify account's SponsoredOwnerCount
|
||||
@@ -1741,9 +1740,8 @@ addEmptyHolding(
|
||||
tx,
|
||||
sleDst,
|
||||
priorBalance,
|
||||
sponsorAccountID
|
||||
? view.peek(keylet::account(*sponsorAccountID))
|
||||
: std::optional<std::shared_ptr<SLE>>(std::nullopt),
|
||||
sponsorAccountID ? view.peek(keylet::account(*sponsorAccountID))
|
||||
: std::shared_ptr<SLE>(),
|
||||
1);
|
||||
!isTesSuccess(ret))
|
||||
return tecNO_LINE_INSUF_RESERVE;
|
||||
@@ -1850,7 +1848,7 @@ authorizeMPToken(
|
||||
// items. This is similar to the reserve requirements of trust lines.
|
||||
// If PreFunded Sponsor, it must be checked whether sufficient
|
||||
// ReserveCount exists.
|
||||
if (ownerCount(sponsor.value_or(sleAcct)) >= 2 ||
|
||||
if (ownerCount(sponsor ? sponsor : sleAcct) >= 2 ||
|
||||
isSponsoredAndPreFunded)
|
||||
{
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
@@ -2036,7 +2034,7 @@ trustCreate(
|
||||
uFlags |= (bSetHigh ? lsfLowNoRipple : lsfHighNoRipple);
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<SLE>> sponsorSle = std::nullopt;
|
||||
std::shared_ptr<SLE> sponsorSle = {};
|
||||
if (sponsorAccountID)
|
||||
sponsorSle = view.peek(keylet::account(*sponsorAccountID));
|
||||
|
||||
@@ -2098,7 +2096,7 @@ removeEmptyHolding(
|
||||
if (!sleLowAccount)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
adjustOwnerCount(view, sleLowAccount, std::nullopt, -1, journal);
|
||||
adjustOwnerCount(view, sleLowAccount, {}, -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.
|
||||
@@ -2113,7 +2111,7 @@ removeEmptyHolding(
|
||||
if (!sleHighAccount)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
adjustOwnerCount(view, sleHighAccount, std::nullopt, -1, journal);
|
||||
adjustOwnerCount(view, sleHighAccount, {}, -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.
|
||||
|
||||
@@ -298,6 +298,7 @@ public:
|
||||
sponsor::as(sponsor, tfSponsorReserve),
|
||||
msig(sfSponsorSignature, {signer1}),
|
||||
ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
env(signers(sponsor, 2, {{signer1, 1}, {signer2, 1}}));
|
||||
env.close();
|
||||
|
||||
@@ -589,7 +589,7 @@ AMMWithdraw::withdraw(
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
auto const balance = (*sleAccount)[sfBalance].xrp();
|
||||
std::uint32_t const count =
|
||||
ownerCount(sponsorSle ? *sponsorSle : sleAccount);
|
||||
ownerCount(sponsorSle ? sponsorSle : sleAccount);
|
||||
if (count >= 2)
|
||||
{
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
@@ -598,7 +598,7 @@ AMMWithdraw::withdraw(
|
||||
sleAccount,
|
||||
std::max(priorBalance, balance),
|
||||
sponsor ? view.read(keylet::account(*sponsor))
|
||||
: std::optional<std::shared_ptr<SLE const>>{},
|
||||
: std::shared_ptr<SLE const>(),
|
||||
1);
|
||||
!isTesSuccess(ret))
|
||||
return ret;
|
||||
|
||||
@@ -329,7 +329,7 @@ CashCheck::doApply()
|
||||
auto const sleDst = psb.peek(keylet::account(account_));
|
||||
|
||||
auto const sponsorAcc = getTxReserveSponsorAccountID(ctx_.tx);
|
||||
std::optional<std::shared_ptr<SLE>> sponsorSle = std::nullopt;
|
||||
std::shared_ptr<SLE> sponsorSle = {};
|
||||
if (sponsorAcc)
|
||||
sponsorSle = psb.peek(keylet::account(*sponsorAcc));
|
||||
|
||||
|
||||
@@ -444,7 +444,7 @@ EscrowCreate::doApply()
|
||||
ctx_.tx,
|
||||
sle,
|
||||
mSourceBalance - STAmount(amount).xrp(),
|
||||
std::optional<std::shared_ptr<SLE const>>(),
|
||||
{},
|
||||
1);
|
||||
!isTesSuccess(ret))
|
||||
return tecUNFUNDED;
|
||||
@@ -780,7 +780,7 @@ escrowUnlockApplyHelper<Issue>(
|
||||
{
|
||||
// Can the account cover the trust line's reserve?
|
||||
auto const sponsorAcc = getTxReserveSponsorAccountID(tx);
|
||||
std::optional<std::shared_ptr<SLE>> sponsorSle = std::nullopt;
|
||||
std::shared_ptr<SLE> sponsorSle = {};
|
||||
if (sponsorAcc)
|
||||
sponsorSle = view.peek(keylet::account(*sponsorAcc));
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
|
||||
@@ -88,8 +88,9 @@ MPTokenIssuanceCreate::create(
|
||||
if (!acct)
|
||||
return Unexpected(tecINTERNAL); // LCOV_EXCL_LINE
|
||||
|
||||
auto const sponsor =
|
||||
!isPseudoAccount((acct)) ? getTxReserveSponsor(view, tx) : std::nullopt;
|
||||
auto const sponsor = !isPseudoAccount((acct))
|
||||
? getTxReserveSponsor(view, tx)
|
||||
: std::shared_ptr<SLE>();
|
||||
if (args.priorBalance)
|
||||
{
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
|
||||
@@ -407,7 +407,7 @@ NFTokenAcceptOffer::transferNFToken(
|
||||
{
|
||||
auto const sponsor = account_ == buyer
|
||||
? getTxReserveSponsor(ctx_.view(), ctx_.tx)
|
||||
: std::optional<std::shared_ptr<SLE const>>();
|
||||
: std::shared_ptr<SLE const>();
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx_.view(), ctx_.tx, sleBuyer, buyerBalance, sponsor, 0);
|
||||
!isTesSuccess(ret))
|
||||
|
||||
@@ -280,9 +280,9 @@ insertToken(
|
||||
std::shared_ptr<SLE> const& newPage,
|
||||
AccountID const& owner,
|
||||
std::optional<AccountID> const& sponsor) -> TER {
|
||||
std::optional<std::shared_ptr<SLE>> const sponsorSle = sponsor
|
||||
std::shared_ptr<SLE> const sponsorSle = sponsor
|
||||
? view.peek(keylet::account(*sponsor))
|
||||
: std::optional<std::shared_ptr<SLE>>{std::nullopt};
|
||||
: std::shared_ptr<SLE>();
|
||||
|
||||
if (isReserveSponsored(tx))
|
||||
{
|
||||
|
||||
@@ -369,12 +369,7 @@ PayChanFund::doApply()
|
||||
return ret;
|
||||
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
ctx_.view(),
|
||||
ctx_.tx,
|
||||
sle,
|
||||
balance - ctx_.tx[sfAmount],
|
||||
std::optional<std::shared_ptr<SLE const>>(),
|
||||
0);
|
||||
ctx_.view(), ctx_.tx, sle, balance - ctx_.tx[sfAmount], {}, 0);
|
||||
!isTesSuccess(ret))
|
||||
return tecUNFUNDED;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ SetOracle::preclaim(PreclaimContext const& ctx)
|
||||
static bool
|
||||
adjustOwnerCount(
|
||||
ApplyContext& ctx,
|
||||
std::optional<std::shared_ptr<SLE>> const& sponsor,
|
||||
std::shared_ptr<SLE> const& sponsor,
|
||||
int count)
|
||||
{
|
||||
if (auto const sleAccount =
|
||||
|
||||
@@ -354,11 +354,12 @@ SetTrust::doApply()
|
||||
// could use the extra XRP for their own purposes.
|
||||
auto const txSponsorAcc = getTxReserveSponsorAccountID(ctx_.tx);
|
||||
|
||||
std::optional<std::shared_ptr<SLE>> txSponsorSle = std::nullopt;
|
||||
std::shared_ptr<SLE> txSponsorSle = {};
|
||||
if (txSponsorAcc)
|
||||
txSponsorSle = view().peek(keylet::account(*txSponsorAcc));
|
||||
|
||||
std::uint32_t const uOwnerCount = ownerCount(txSponsorSle.value_or(sle));
|
||||
std::uint32_t const uOwnerCount =
|
||||
ownerCount(txSponsorSle ? txSponsorSle : sle);
|
||||
|
||||
bool const isSponsoredAndPreFunded =
|
||||
txSponsorSle && !isSponsorReserveCoSigning(ctx_.tx);
|
||||
|
||||
@@ -179,7 +179,7 @@ SponsorshipTransfer::preclaim(PreclaimContext const& ctx)
|
||||
{
|
||||
// transfer sponsor
|
||||
// check if the object owner isn't the same as the new sponsor
|
||||
if ((*newSponsor)->getAccountID(sfAccount) == owner)
|
||||
if (newSponsor->getAccountID(sfAccount) == owner)
|
||||
// checked in above
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
}
|
||||
@@ -210,7 +210,7 @@ SponsorshipTransfer::preclaim(PreclaimContext const& ctx)
|
||||
if (accSle->isFieldPresent(sfSponsorAccount))
|
||||
{
|
||||
// check not same account
|
||||
if ((*newSponsor)->getAccountID(sfAccount) ==
|
||||
if (newSponsor->getAccountID(sfAccount) ==
|
||||
accSle->getAccountID(sfAccount))
|
||||
// already checked in Transactor::preflight1()
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
@@ -138,7 +138,7 @@ VaultDelete::doApply()
|
||||
return tefBAD_LEDGER;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
adjustOwnerCount(view(), pseudoAcct, std::nullopt, -1, j_);
|
||||
adjustOwnerCount(view(), pseudoAcct, {}, -1, j_);
|
||||
|
||||
view().erase(mpt);
|
||||
|
||||
|
||||
@@ -1058,9 +1058,8 @@ applyCreateAccountAttestations(
|
||||
|
||||
// Check reserve
|
||||
auto const balance = (*sleDoor)[sfBalance];
|
||||
auto const sponsor = std::optional<std::shared_ptr<SLE const>>();
|
||||
if (auto const ret = checkInsufficientReserve(
|
||||
psb, tx, sleDoor, balance, sponsor, 1);
|
||||
if (auto const ret =
|
||||
checkInsufficientReserve(psb, tx, sleDoor, balance, {}, 1);
|
||||
!isTesSuccess(ret))
|
||||
return Unexpected(ret); // tecINSUFFICIENT_RESERVE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user