@@ -61,10 +61,7 @@ MPTokenIssuance::isAnyFrozen(std::initializer_list<AccountID> const& accounts, i
6161 {
6262 if (isIndividualFrozen (account))
6363 return true ;
64- }
6564
66- for (auto const & account : accounts)
67- {
6865 if (isVaultPseudoAccountFrozen (readView_, account, mptIssue_, depth))
6966 return true ;
7067 }
@@ -157,18 +154,17 @@ WritableMPTokenIssuance::authorizeMPToken(
157154 // - delete the MPToken
158155 if (flags & tfMPTUnauthorize)
159156 {
160- auto const mptokenKey = keylet::mptoken (mptID_, account);
161- auto const sleMpt = applyView_.peek (mptokenKey);
162- if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0 )
157+ WritableMPToken mptoken (*this , account);
158+ if (!mptoken.exists () || (*mptoken)[sfMPTAmount] != 0 )
163159 return tecINTERNAL; // LCOV_EXCL_LINE
164160
165161 if (!applyView_.dirRemove (
166- keylet::ownerDir (account), (*sleMpt )[sfOwnerNode], sleMpt ->key (), false ))
162+ keylet::ownerDir (account), (*mptoken )[sfOwnerNode], mptoken ->key (), false ))
167163 return tecINTERNAL; // LCOV_EXCL_LINE
168164
169165 wrappedAcct.adjustOwnerCount (-1 , journal);
170166
171- applyView_ .erase (sleMpt );
167+ mptoken .erase ();
172168 return tesSUCCESS;
173169 }
174170
@@ -371,8 +367,7 @@ WritableMPTokenIssuance::enforceMPTokenAuthorization(
371367 if (account == mutableSle_->at (sfIssuer))
372368 return tefINTERNAL; // LCOV_EXCL_LINE
373369
374- auto const keylet = keylet::mptoken (mptID_, account);
375- auto const sleToken = readView_.read (keylet); // NOTE: might be null
370+ MPToken mptoken (*this , account);
376371 auto const maybeDomainID = mutableSle_->at (~sfDomainID);
377372 bool expired = false ;
378373 bool const authorizedByDomain = [&]() -> bool {
@@ -388,7 +383,7 @@ WritableMPTokenIssuance::enforceMPTokenAuthorization(
388383 return false ;
389384 }();
390385
391- if (!authorizedByDomain && sleToken == nullptr )
386+ if (!authorizedByDomain && !mptoken. exists () )
392387 {
393388 // Could not find MPToken and won't create one, could be either of:
394389 //
@@ -411,14 +406,14 @@ WritableMPTokenIssuance::enforceMPTokenAuthorization(
411406 // We found an MPToken, but sfDomainID is not set, so this is a classic
412407 // MPToken which requires authorization by the token issuer.
413408 XRPL_ASSERT (
414- sleToken != nullptr && !maybeDomainID,
409+ mptoken. exists () && !maybeDomainID,
415410 " xrpl::enforceMPTokenAuthorization : found MPToken" );
416- if (sleToken ->isFlag (lsfMPTAuthorized))
411+ if (mptoken ->isFlag (lsfMPTAuthorized))
417412 return tesSUCCESS;
418413
419414 return tecNO_AUTH;
420415 }
421- if (authorizedByDomain && sleToken != nullptr )
416+ if (authorizedByDomain && mptoken. exists () )
422417 {
423418 // Found an MPToken, authorized by the domain. Ignore authorization flag
424419 // lsfMPTAuthorized because it is meaningless. Return tesSUCCESS
@@ -430,7 +425,7 @@ WritableMPTokenIssuance::enforceMPTokenAuthorization(
430425 // Could not find MPToken but there should be one because we are
431426 // authorized by domain. Proceed to create it, then return tesSUCCESS
432427 XRPL_ASSERT (
433- maybeDomainID && sleToken == nullptr ,
428+ maybeDomainID && !mptoken. exists () ,
434429 " xrpl::enforceMPTokenAuthorization : new MPToken for domain" );
435430 if (auto const err = authorizeMPToken (
436431 priorBalance, // priorBalance
@@ -687,22 +682,21 @@ rippleUnlockEscrowMPT(
687682 return tecINTERNAL;
688683 } // LCOV_EXCL_STOP
689684 // Decrease the MPT Holder EscrowedAmount
690- auto const mptokenID = keylet::mptoken (mptIssue.getMptID (), sender);
691- auto sle = view.peek (mptokenID);
692- if (!sle)
685+ WritableMPToken mpt (mptIssuance, sender);
686+ if (!mpt.exists ())
693687 { // LCOV_EXCL_START
694688 JLOG (j.error ()) << " rippleUnlockEscrowMPT: MPToken not found for " << sender;
695689 return tecOBJECT_NOT_FOUND;
696690 } // LCOV_EXCL_STOP
697691
698- if (!sle ->isFieldPresent (sfLockedAmount))
692+ if (!mpt ->isFieldPresent (sfLockedAmount))
699693 { // LCOV_EXCL_START
700694 JLOG (j.error ()) << " rippleUnlockEscrowMPT: no locked amount in MPToken for "
701695 << to_string (sender);
702696 return tecINTERNAL;
703697 } // LCOV_EXCL_STOP
704698
705- auto const locked = sle ->getFieldU64 (sfLockedAmount);
699+ auto const locked = mpt ->getFieldU64 (sfLockedAmount);
706700 auto const delta = grossAmount.mpt ().value ();
707701
708702 // Underflow check for subtraction
@@ -715,10 +709,10 @@ rippleUnlockEscrowMPT(
715709
716710 auto const newLocked = locked - delta;
717711 if (newLocked == 0 )
718- sle ->makeFieldAbsent (sfLockedAmount);
712+ mpt ->makeFieldAbsent (sfLockedAmount);
719713 else
720- sle ->setFieldU64 (sfLockedAmount, newLocked);
721- view .update (sle );
714+ mpt ->setFieldU64 (sfLockedAmount, newLocked);
715+ mpt .update ();
722716
723717 // Note: The gross amount is the amount that was locked, the net
724718 // amount is the amount that is being unlocked. The difference is the fee
@@ -778,15 +772,15 @@ MPTokenIssuance::accountHolds(
778772
779773 STAmount amount;
780774
781- auto const sleMpt = readView_. read ( keylet::mptoken (mptID_ , account) );
775+ MPToken mpt (* this , account);
782776
783- if (!sleMpt )
777+ if (!mpt. exists () )
784778 amount.clear (mptIssue_);
785779 else if (zeroIfFrozen == fhZERO_IF_FROZEN && isFrozen (account))
786780 amount.clear (mptIssue_);
787781 else
788782 {
789- amount = STAmount{mptIssue_, sleMpt ->getFieldU64 (sfMPTAmount)};
783+ amount = STAmount{mptIssue_, mpt ->getFieldU64 (sfMPTAmount)};
790784
791785 // Only if auth check is needed, as it needs to do an additional read
792786 // operation. Note featureSingleAssetVault will affect error codes.
@@ -800,7 +794,7 @@ MPTokenIssuance::accountHolds(
800794 {
801795 // if auth is enabled on the issuance and mpt is not authorized,
802796 // clear amount
803- if (sle_ && sle_->isFlag (lsfMPTRequireAuth) && !sleMpt ->isFlag (lsfMPTAuthorized))
797+ if (sle_ && sle_->isFlag (lsfMPTRequireAuth) && !mpt ->isFlag (lsfMPTAuthorized))
804798 amount.clear (mptIssue_);
805799 }
806800 }
0 commit comments