Skip to content

Commit

Permalink
Merge pull request #6 from shawnxie999/mpt-old-improvements
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
gregtatcam authored Jan 4, 2024
2 parents f7853f5 + fd444d0 commit 4ed11a6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 44 deletions.
19 changes: 5 additions & 14 deletions src/ripple/app/tx/impl/MPTokenAuthorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ MPTokenAuthorize::preflight(PreflightContext const& ctx)
if (ctx.tx.getFlags() & tfMPTokenAuthorizeMask)
return temINVALID_FLAG;

auto const accountID = ctx.tx[sfAccount];
auto const holderID = ctx.tx[~sfMPTokenHolder];
if (holderID && accountID == holderID)
if (ctx.tx[sfAccount] == ctx.tx[~sfMPTokenHolder])
return temMALFORMED;

return preflight2(ctx);
Expand All @@ -62,8 +60,6 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx)

std::uint32_t const mptIssuanceFlags = sleMptIssuance->getFieldU32(sfFlags);

std::shared_ptr<SLE const> sleMpt;

// If tx is submitted by issuer, they would either try to do the following
// for allowlisting:
// 1. authorize an account
Expand Down Expand Up @@ -97,7 +93,7 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx)
if (holderID)
return temMALFORMED;

sleMpt =
std::shared_ptr<SLE const> sleMpt =
ctx.view.read(keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], accountID));

// if holder wants to delete/unauthorize a mpt
Expand All @@ -110,11 +106,8 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx)
return tecHAS_OBLIGATIONS;
}
// if holder wants to use and create a mpt
else
{
if (sleMpt)
return tecMPTOKEN_EXISTS;
}
else if (sleMpt)
return tecMPTOKEN_EXISTS;

return tesSUCCESS;
}
Expand Down Expand Up @@ -196,8 +189,7 @@ MPTokenAuthorize::doApply()
false))
return tecINTERNAL;

adjustOwnerCount(
view(), sleAcct, -1, beast::Journal{beast::Journal::getNullSink()});
adjustOwnerCount(view(), sleAcct, -1, j_);

view().erase(sleMpt);
return tesSUCCESS;
Expand Down Expand Up @@ -236,7 +228,6 @@ MPTokenAuthorize::doApply()
(*mptoken)[sfAccount] = account_;
(*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID;
(*mptoken)[sfFlags] = 0;
(*mptoken)[sfMPTAmount] = 0;
(*mptoken)[sfOwnerNode] = *ownerNode;
(*mptoken)[sfMPTokenNode] = *mptNode;
view().insert(mptoken);
Expand Down
6 changes: 0 additions & 6 deletions src/ripple/app/tx/impl/MPTokenIssuanceCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ MPTokenIssuanceCreate::preflight(PreflightContext const& ctx)
return preflight2(ctx);
}

TER
MPTokenIssuanceCreate::preclaim(PreclaimContext const& ctx)
{
return tesSUCCESS;
}

TER
MPTokenIssuanceCreate::doApply()
{
Expand Down
3 changes: 0 additions & 3 deletions src/ripple/app/tx/impl/MPTokenIssuanceCreate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class MPTokenIssuanceCreate : public Transactor
static NotTEC
preflight(PreflightContext const& ctx);

static TER
preclaim(PreclaimContext const& ctx);

TER
doApply() override;
};
Expand Down
6 changes: 1 addition & 5 deletions src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ MPTokenIssuanceDestroy::doApply()

view().erase(mpt);

adjustOwnerCount(
view(),
view().peek(keylet::account(issuer)),
-1,
beast::Journal{beast::Journal::getNullSink()});
adjustOwnerCount(view(), view().peek(keylet::account(issuer)), -1, j_);

return tesSUCCESS;
}
Expand Down
24 changes: 12 additions & 12 deletions src/ripple/app/tx/impl/MPTokenIssuanceSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx)
if (!ctx.rules.enabled(featureMPTokensV1))
return temDISABLED;

// check flags
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;

auto const txFlags = ctx.tx.getFlags();

// check flags
if (txFlags & tfMPTokenIssuanceSetMask)
return temINVALID_FLAG;
// fails if both flags are set
Expand Down Expand Up @@ -68,17 +68,17 @@ MPTokenIssuanceSet::preclaim(PreclaimContext const& ctx)
if ((*sleMptIssuance)[sfIssuer] != ctx.tx[sfAccount])
return tecNO_PERMISSION;

auto const holderID = ctx.tx[~sfMPTokenHolder];

// make sure holder account exists
if (holderID && !ctx.view.exists(keylet::account(*holderID)))
return tecNO_DST;

// the mptoken must exist
if (holderID &&
!ctx.view.exists(
keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], *holderID)))
return tecOBJECT_NOT_FOUND;
if (auto const holderID = ctx.tx[~sfMPTokenHolder])
{
// make sure holder account exists
if (!ctx.view.exists(keylet::account(*holderID)))
return tecNO_DST;

// the mptoken must exist
if (!ctx.view.exists(
keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], *holderID)))
return tecOBJECT_NOT_FOUND;
}

return tesSUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/impl/LedgerFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ LedgerFormats::LedgerFormats()
{
{sfAccount, soeREQUIRED},
{sfMPTokenIssuanceID, soeREQUIRED},
{sfMPTAmount, soeREQUIRED},
{sfMPTAmount, soeDEFAULT},
{sfLockedAmount, soeDEFAULT},
{sfOwnerNode, soeREQUIRED},
{sfMPTokenNode, soeREQUIRED},
Expand Down
6 changes: 3 additions & 3 deletions src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ripple {

class MPToken_test : public beast::unit_test::suite
{
bool
[[nodiscard]] bool
checkMPTokenAmount(
test::jtx::Env const& env,
ripple::uint256 const mptIssuanceid,
Expand All @@ -40,7 +40,7 @@ class MPToken_test : public beast::unit_test::suite
return amount == expectedAmount;
}

bool
[[nodiscard]] bool
checkMPTokenIssuanceFlags(
test::jtx::Env const& env,
ripple::uint256 const mptIssuanceid,
Expand All @@ -54,7 +54,7 @@ class MPToken_test : public beast::unit_test::suite
return expectedFlags == mptIssuanceFlags;
}

bool
[[nodiscard]] bool
checkMPTokenFlags(
test::jtx::Env const& env,
ripple::uint256 const mptIssuanceid,
Expand Down

0 comments on commit 4ed11a6

Please sign in to comment.