mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-23 23:20:33 +00:00
refactor based on Vito's comments
This commit is contained in:
@@ -400,25 +400,33 @@ public:
|
||||
|
||||
struct ReserveContext
|
||||
{
|
||||
AccountID const accountID;
|
||||
SLE::pointer accountSle;
|
||||
std::optional<AccountID> const sponsorID;
|
||||
SLE::pointer sponsorSle;
|
||||
SLE::pointer sponsorshipSle;
|
||||
|
||||
[[nodiscard]] AccountID const
|
||||
accountID() const
|
||||
{
|
||||
return accountSle->getAccountID(sfAccount);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<AccountID> const
|
||||
sponsorID() const
|
||||
{
|
||||
return sponsorSle ? std::optional<AccountID>{sponsorSle->getAccountID(sfAccount)}
|
||||
: std::nullopt;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool
|
||||
isSponsored() const
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
sponsorID.has_value() == !!sponsorSle,
|
||||
"ReserveContext::isSponsored : sponsor existence matches sponsorSle existence");
|
||||
return sponsorID.has_value();
|
||||
return sponsorSle != nullptr;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool
|
||||
hasSponsorshipObj() const
|
||||
{
|
||||
return !!sponsorshipSle;
|
||||
return sponsorshipSle != nullptr;
|
||||
}
|
||||
|
||||
static ReserveContext
|
||||
|
||||
@@ -426,9 +426,7 @@ ReserveContext::makeFromTx(ApplyView& view, STTx const& tx)
|
||||
isReserveSponsored(tx) ? std::optional<AccountID>{tx[sfSponsor]} : std::nullopt;
|
||||
|
||||
return {
|
||||
.accountID = account,
|
||||
.accountSle = view.peek(keylet::account(account)),
|
||||
.sponsorID = sponsor,
|
||||
.sponsorSle = sponsor ? view.peek(keylet::account(*sponsor)) : nullptr,
|
||||
.sponsorshipSle = sponsor ? view.peek(keylet::sponsorship(*sponsor, account)) : nullptr,
|
||||
};
|
||||
@@ -444,9 +442,7 @@ ReserveContext::makeFromAccount(ApplyView& view, SLE::pointer accountSle, SLE::p
|
||||
std::optional<AccountID> const sponsorID =
|
||||
sponsorSle ? std::optional<AccountID>{sponsorSle->getAccountID(sfAccount)} : std::nullopt;
|
||||
return {
|
||||
.accountID = accountID,
|
||||
.accountSle = accountSle,
|
||||
.sponsorID = sponsorID,
|
||||
.sponsorSle = sponsorSle,
|
||||
.sponsorshipSle =
|
||||
sponsorID ? view.peek(keylet::sponsorship(*sponsorID, accountID)) : nullptr,
|
||||
@@ -461,9 +457,7 @@ ReserveContext::makeFromObject(ApplyView& view, SLE::ref objectSle, SLE::pointer
|
||||
std::optional<AccountID> const sponsorID =
|
||||
sponsorSle ? std::optional<AccountID>{sponsorSle->getAccountID(sfAccount)} : std::nullopt;
|
||||
return {
|
||||
.accountID = accountID,
|
||||
.accountSle = ownerSle,
|
||||
.sponsorID = sponsorID,
|
||||
.sponsorSle = sponsorSle,
|
||||
.sponsorshipSle =
|
||||
sponsorID ? view.peek(keylet::sponsorship(*sponsorID, accountID)) : nullptr,
|
||||
|
||||
@@ -243,14 +243,14 @@ adjustOwnerCount(
|
||||
view,
|
||||
reserveCtx.accountSle,
|
||||
sfSponsoredOwnerCount,
|
||||
reserveCtx.accountID,
|
||||
reserveCtx.accountID(),
|
||||
ownerCountAdj,
|
||||
j);
|
||||
adjustOwnerCountValue(
|
||||
view,
|
||||
reserveCtx.sponsorSle,
|
||||
sfSponsoringOwnerCount,
|
||||
*reserveCtx.sponsorID,
|
||||
reserveCtx.sponsorID().value(),
|
||||
ownerCountAdj,
|
||||
j);
|
||||
|
||||
@@ -263,14 +263,14 @@ adjustOwnerCount(
|
||||
view,
|
||||
reserveCtx.sponsorshipSle,
|
||||
sfRemainingOwnerCount,
|
||||
*reserveCtx.sponsorID,
|
||||
reserveCtx.sponsorID().value(),
|
||||
-ownerCountAdj,
|
||||
j,
|
||||
false);
|
||||
}
|
||||
}
|
||||
adjustOwnerCountValue(
|
||||
view, reserveCtx.accountSle, sfOwnerCount, reserveCtx.accountID, ownerCountAdj, j);
|
||||
view, reserveCtx.accountSle, sfOwnerCount, reserveCtx.accountID(), ownerCountAdj, j);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -162,7 +162,7 @@ authorizeMPToken(
|
||||
if (!sleAcct)
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
auto const reserveCtx = account == ctx.reserveContext.accountID
|
||||
auto const reserveCtx = account == ctx.reserveContext.accountID()
|
||||
? ctx.reserveContext
|
||||
: ReserveContext::makeFromAccount(view, sleAcct, nullptr);
|
||||
|
||||
@@ -945,7 +945,7 @@ checkCreateMPT(
|
||||
beast::Journal j)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
reserveCtx.accountID == holder, "xrpl::checkCreateMPT : reserve context matches holder");
|
||||
reserveCtx.accountID() == holder, "xrpl::checkCreateMPT : reserve context matches holder");
|
||||
|
||||
if (mptIssue.getIssuer() == holder)
|
||||
return tesSUCCESS;
|
||||
|
||||
@@ -271,7 +271,7 @@ insertToken(ApplyViewContext& ctx, AccountID owner, STObject&& nft)
|
||||
// the NFT.
|
||||
SLE::pointer const page = getPageForToken(
|
||||
ctx, owner, nft[sfNFTokenID], [](ApplyViewContext& ctx, AccountID const& owner) {
|
||||
auto const reserveCtx = owner == ctx.reserveContext.accountID
|
||||
auto const reserveCtx = owner == ctx.reserveContext.accountID()
|
||||
? ctx.reserveContext
|
||||
: ReserveContext::makeFromAccount(
|
||||
ctx.view, ctx.view.peek(keylet::account(owner)), nullptr);
|
||||
|
||||
@@ -662,7 +662,7 @@ addEmptyHolding(
|
||||
if (view.read(index))
|
||||
return tecDUPLICATE;
|
||||
|
||||
auto const reserveCtx = accountID == ctx.reserveContext.accountID
|
||||
auto const reserveCtx = accountID == ctx.reserveContext.accountID()
|
||||
? ctx.reserveContext
|
||||
: ReserveContext::makeFromAccount(view, sleDst, nullptr);
|
||||
SLE::pointer const sponsorSle = isPseudoAccount(sleDst) ? nullptr : reserveCtx.sponsorSle;
|
||||
|
||||
@@ -733,7 +733,7 @@ BookStep<TIn, TOut, TDerived>::forEachOffer(
|
||||
// Therefore, the owner count remains the same.
|
||||
if (auto const err = checkCreateMPT(
|
||||
sb,
|
||||
ReserveContext{owner, sb.peek(keylet::account(owner)), {}, nullptr, nullptr},
|
||||
ReserveContext::makeFromAccount(sb, sb.peek(keylet::account(owner)), nullptr),
|
||||
assetIn.get<MPTIssue>(),
|
||||
owner,
|
||||
j_);
|
||||
|
||||
@@ -413,12 +413,7 @@ MPTEndpointOfferCrossingStep::checkCreateMPTForStep(ApplyView& view, xrpl::DebtD
|
||||
// crossed. See CreateOffer::applyGuts() for reserve check.
|
||||
if (auto const err = xrpl::checkCreateMPT(
|
||||
view,
|
||||
ReserveContext{
|
||||
.accountID = dst_,
|
||||
.accountSle = view.peek(keylet::account(dst_)),
|
||||
.sponsorID = {},
|
||||
.sponsorSle = nullptr,
|
||||
.sponsorshipSle = nullptr},
|
||||
ReserveContext::makeFromAccount(view, view.peek(keylet::account(dst_)), nullptr),
|
||||
mptIssue_,
|
||||
dst_,
|
||||
j_);
|
||||
|
||||
Reference in New Issue
Block a user