Skip to content

Commit 291e287

Browse files
committed
cleanup
1 parent b243732 commit 291e287

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed

src/libxrpl/ledger/helpers/MPTokenHelpers.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/libxrpl/tx/transactors/check/CheckCash.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ CheckCash::preclaim(PreclaimContext const& ctx)
195195

196196
// However, the trustline from destination to issuer may not
197197
// be frozen.
198-
IOUToken wrapped(ctx.view, Issue{currency, issuerId});
199-
if (wrapped.isFrozen(dstId))
198+
if (iouToken.isFrozen(dstId))
200199
{
201200
JLOG(ctx.j.warn()) << "Cashing a check to a frozen trustline.";
202201
return tecFROZEN;

src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ tokenOfferCreatePreclaim(
830830
std::optional<AccountID> const& owner,
831831
std::uint32_t txFlags)
832832
{
833+
IOUToken token(view, amount.issue());
833834
if (!(nftFlags & nft::flagCreateTrustLines) && !amount.native() && xferFee)
834835
{
835836
if (!view.exists(keylet::account(nftIssuer)))
@@ -843,13 +844,12 @@ tokenOfferCreatePreclaim(
843844
!view.read(keylet::line(nftIssuer, amount.issue())))
844845
return tecNO_LINE;
845846
}
846-
else if (!view.exists(keylet::line(nftIssuer, amount.issue())))
847+
else if (!token.hasHolder(nftIssuer))
847848
{
848849
return tecNO_LINE;
849850
}
850851

851-
IOUToken wrapped(view, amount.issue());
852-
if (wrapped.isFrozen(nftIssuer))
852+
if (token.isFrozen(nftIssuer))
853853
return tecFROZEN;
854854
}
855855

@@ -862,7 +862,7 @@ tokenOfferCreatePreclaim(
862862
return tefNFTOKEN_IS_NOT_TRANSFERABLE;
863863
}
864864

865-
if (IOUToken(view, amount.issue()).isFrozen(acctID))
865+
if (token.isFrozen(acctID))
866866
return tecFROZEN;
867867

868868
// If this is an offer to buy the token, the account must have the

src/libxrpl/tx/transactors/vault/VaultDeposit.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ VaultDeposit::preclaim(PreclaimContext const& ctx)
6262
// LCOV_EXCL_STOP
6363
}
6464

65-
auto const mptIssuance = MPTokenIssuance(ctx.view, vaultShare);
66-
if (!mptIssuance)
65+
auto const shareIssuance = MPTokenIssuance(ctx.view, vaultShare);
66+
if (!shareIssuance)
6767
{
6868
// LCOV_EXCL_START
6969
JLOG(ctx.j.error()) << "VaultDeposit: missing issuance of vault shares.";
7070
return tefINTERNAL;
7171
// LCOV_EXCL_STOP
7272
}
7373

74-
if (mptIssuance->isFlag(lsfMPTLocked))
74+
if (shareIssuance->isFlag(lsfMPTLocked))
7575
{
7676
// LCOV_EXCL_START
7777
JLOG(ctx.j.error()) << "VaultDeposit: issuance of vault shares is locked.";
@@ -84,12 +84,12 @@ VaultDeposit::preclaim(PreclaimContext const& ctx)
8484
return vaultAsset.holds<Issue>() ? tecFROZEN : tecLOCKED;
8585

8686
// Cannot deposit if the shares of the vault are frozen
87-
if (MPTokenIssuance(ctx.view, vaultShare).isFrozen(account))
87+
if (shareIssuance.isFrozen(account))
8888
return tecLOCKED;
8989

9090
if (vault->isFlag(lsfVaultPrivate) && account != vault->at(sfOwner))
9191
{
92-
auto const maybeDomainID = mptIssuance->at(~sfDomainID);
92+
auto const maybeDomainID = shareIssuance->at(~sfDomainID);
9393
// Since this is a private vault and the account is not its owner, we
9494
// perform authorization check based on DomainID read from mptIssuance.
9595
// Had the vault shares been a regular MPToken, we would allow

0 commit comments

Comments
 (0)