diff --git a/include/xrpl/ledger/helpers/MPTokenHelpers.h b/include/xrpl/ledger/helpers/MPTokenHelpers.h index ec05a32c8b..ba834392bf 100644 --- a/include/xrpl/ledger/helpers/MPTokenHelpers.h +++ b/include/xrpl/ledger/helpers/MPTokenHelpers.h @@ -231,29 +231,12 @@ createMPToken( SLE::ref sponsorSle, std::uint32_t const flags); -TER -checkCreateMPT( - xrpl::ApplyViewContext& ctx, - xrpl::MPTIssue const& mptIssue, - xrpl::AccountID const& holder, - beast::Journal j); - -inline TER -checkCreateMPT( - xrpl::ApplyViewContext&& ctx, - xrpl::MPTIssue const& mptIssue, - xrpl::AccountID const& holder, - beast::Journal j) -{ - return checkCreateMPT(ctx, mptIssue, holder, j); -} - TER checkCreateMPT( ApplyView& view, + ReserveContext const& reserveCtx, xrpl::MPTIssue const& mptIssue, xrpl::AccountID const& holder, - SLE::ref sponsorSle, beast::Journal j); //------------------------------------------------------------------------------ diff --git a/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp b/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp index 4f2b199670..0df68f588c 100644 --- a/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp @@ -939,14 +939,18 @@ createMPToken( return tesSUCCESS; } -static TER -checkCreateMPTWithReserve( +TER +checkCreateMPT( ApplyView& view, ReserveContext const& reserveCtx, xrpl::MPTIssue const& mptIssue, xrpl::AccountID const& holder, beast::Journal j) { + XRPL_ASSERT( + reserveCtx.accountID == holder, + "xrpl::checkCreateMPTWithReserve : reserve context matches holder"); + if (mptIssue.getIssuer() == holder) return tesSUCCESS; @@ -971,35 +975,6 @@ checkCreateMPTWithReserve( return tesSUCCESS; } -TER -checkCreateMPT( - xrpl::ApplyViewContext& ctx, - xrpl::MPTIssue const& mptIssue, - xrpl::AccountID const& holder, - beast::Journal j) -{ - return checkCreateMPTWithReserve(ctx.view, ctx.reserveContext, mptIssue, holder, j); -} - -TER -checkCreateMPT( - ApplyView& view, - xrpl::MPTIssue const& mptIssue, - xrpl::AccountID const& holder, - SLE::ref sponsorSle, - beast::Journal j) -{ - auto const sponsorID = sponsorSle - ? std::optional{sponsorSle->getAccountID(sfAccount)} - : std::optional{}; - return checkCreateMPTWithReserve( - view, - ReserveContext{holder, view.peek(keylet::account(holder)), sponsorID, sponsorSle, nullptr}, - mptIssue, - holder, - j); -} - std::int64_t maxMPTAmount(SLE const& sleIssuance) { diff --git a/src/libxrpl/tx/paths/BookStep.cpp b/src/libxrpl/tx/paths/BookStep.cpp index 6f31de8805..2fdba82092 100644 --- a/src/libxrpl/tx/paths/BookStep.cpp +++ b/src/libxrpl/tx/paths/BookStep.cpp @@ -731,11 +731,14 @@ BookStep::forEachOffer( // Create MPToken for the offer's owner. No need to check // for the reserve since the offer is removed if it is consumed. // Therefore, the owner count remains the same. - if (auto const err = checkCreateMPT(sb, assetIn.get(), owner, {}, j_); + if (auto const err = checkCreateMPT( + sb, + ReserveContext{owner, sb.peek(keylet::account(owner)), {}, nullptr, nullptr}, + assetIn.get(), + owner, + j_); !isTesSuccess(err)) - { return true; - } } // It shouldn't matter from auth point of view whether it's sb diff --git a/src/libxrpl/tx/paths/MPTEndpointStep.cpp b/src/libxrpl/tx/paths/MPTEndpointStep.cpp index 7a2a0f3361..74d97306d0 100644 --- a/src/libxrpl/tx/paths/MPTEndpointStep.cpp +++ b/src/libxrpl/tx/paths/MPTEndpointStep.cpp @@ -410,7 +410,12 @@ MPTEndpointOfferCrossingStep::checkCreateMPT(ApplyView& view, xrpl::DebtDirectio // for the reserve since the offer doesn't go on the books // if crossed. Insufficient reserve is allowed if the offer // crossed. See CreateOffer::applyGuts() for reserve check. - if (auto const err = xrpl::checkCreateMPT(view, mptIssue_, dst_, {}, j_); + if (auto const err = xrpl::checkCreateMPT( + view, + ReserveContext{dst_, view.peek(keylet::account(dst_)), {}, nullptr, nullptr}, + mptIssue_, + dst_, + j_); !isTesSuccess(err)) { JLOG(j_.trace()) << "MPTEndpointStep::checkCreateMPT: failed create MPT"; diff --git a/src/libxrpl/tx/transactors/check/CheckCash.cpp b/src/libxrpl/tx/transactors/check/CheckCash.cpp index c76184d98a..9be029930f 100644 --- a/src/libxrpl/tx/transactors/check/CheckCash.cpp +++ b/src/libxrpl/tx/transactors/check/CheckCash.cpp @@ -504,8 +504,12 @@ CheckCash::doApply() if (sleDst == nullptr) return tecINSUFFICIENT_RESERVE; - if (auto const err = - checkCreateMPT(applyViewContext, issue, accountID_, j_); + if (auto const err = checkCreateMPT( + applyViewContext.view, + applyViewContext.reserveContext, + issue, + accountID_, + j_); !isTesSuccess(err)) { return err; diff --git a/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp b/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp index 0fdfae1a9a..dba90fdf80 100644 --- a/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp @@ -654,11 +654,15 @@ AMMWithdraw::withdraw( !isTesSuccess(err)) return err; - if (auto const err = checkCreateMPT(view, mptIssue, account, {}, journal); + if (auto const err = checkCreateMPT( + view, + ReserveContext{ + account, view.peek(keylet::account(account)), {}, nullptr, nullptr}, + mptIssue, + account, + journal); !isTesSuccess(err)) - { return err; - } } return tesSUCCESS; };