From 280047bb528eac965c1ec9eea41e87175551cadd Mon Sep 17 00:00:00 2001 From: Shawn Xie Date: Thu, 4 Jan 2024 15:33:25 -0500 Subject: [PATCH 1/2] Minor improvements --- src/ripple/app/tx/impl/MPTokenAuthorize.cpp | 18 ++++---------- .../app/tx/impl/MPTokenIssuanceCreate.cpp | 6 ----- .../app/tx/impl/MPTokenIssuanceCreate.h | 3 --- .../app/tx/impl/MPTokenIssuanceDestroy.cpp | 2 +- src/ripple/app/tx/impl/MPTokenIssuanceSet.cpp | 24 +++++++++---------- src/ripple/protocol/impl/LedgerFormats.cpp | 2 +- src/test/app/MPToken_test.cpp | 3 +++ 7 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/ripple/app/tx/impl/MPTokenAuthorize.cpp b/src/ripple/app/tx/impl/MPTokenAuthorize.cpp index a1c66ce7b74..8bfde47c74b 100644 --- a/src/ripple/app/tx/impl/MPTokenAuthorize.cpp +++ b/src/ripple/app/tx/impl/MPTokenAuthorize.cpp @@ -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); @@ -62,8 +60,6 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx) std::uint32_t const mptIssuanceFlags = sleMptIssuance->getFieldU32(sfFlags); - std::shared_ptr sleMpt; - // If tx is submitted by issuer, they would either try to do the following // for allowlisting: // 1. authorize an account @@ -97,7 +93,7 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx) if (holderID) return temMALFORMED; - sleMpt = + std::shared_ptr sleMpt = ctx.view.read(keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], accountID)); // if holder wants to delete/unauthorize a mpt @@ -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; } @@ -197,7 +190,7 @@ MPTokenAuthorize::doApply() return tecINTERNAL; adjustOwnerCount( - view(), sleAcct, -1, beast::Journal{beast::Journal::getNullSink()}); + view(), sleAcct, -1, j_); view().erase(sleMpt); return tesSUCCESS; @@ -236,7 +229,6 @@ MPTokenAuthorize::doApply() (*mptoken)[sfAccount] = account_; (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID; (*mptoken)[sfFlags] = 0; - (*mptoken)[sfMPTAmount] = 0; (*mptoken)[sfOwnerNode] = *ownerNode; (*mptoken)[sfMPTokenNode] = *mptNode; view().insert(mptoken); diff --git a/src/ripple/app/tx/impl/MPTokenIssuanceCreate.cpp b/src/ripple/app/tx/impl/MPTokenIssuanceCreate.cpp index 38a57c9deeb..dd8a90355fe 100644 --- a/src/ripple/app/tx/impl/MPTokenIssuanceCreate.cpp +++ b/src/ripple/app/tx/impl/MPTokenIssuanceCreate.cpp @@ -58,12 +58,6 @@ MPTokenIssuanceCreate::preflight(PreflightContext const& ctx) return preflight2(ctx); } -TER -MPTokenIssuanceCreate::preclaim(PreclaimContext const& ctx) -{ - return tesSUCCESS; -} - TER MPTokenIssuanceCreate::doApply() { diff --git a/src/ripple/app/tx/impl/MPTokenIssuanceCreate.h b/src/ripple/app/tx/impl/MPTokenIssuanceCreate.h index 79f56b9beba..c6c2b4b3505 100644 --- a/src/ripple/app/tx/impl/MPTokenIssuanceCreate.h +++ b/src/ripple/app/tx/impl/MPTokenIssuanceCreate.h @@ -36,9 +36,6 @@ class MPTokenIssuanceCreate : public Transactor static NotTEC preflight(PreflightContext const& ctx); - static TER - preclaim(PreclaimContext const& ctx); - TER doApply() override; }; diff --git a/src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp b/src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp index 7ee1280be0a..a1cd4dcd50c 100644 --- a/src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp +++ b/src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp @@ -78,7 +78,7 @@ MPTokenIssuanceDestroy::doApply() view(), view().peek(keylet::account(issuer)), -1, - beast::Journal{beast::Journal::getNullSink()}); + j_); return tesSUCCESS; } diff --git a/src/ripple/app/tx/impl/MPTokenIssuanceSet.cpp b/src/ripple/app/tx/impl/MPTokenIssuanceSet.cpp index 5307b8a979b..8f46379f87c 100644 --- a/src/ripple/app/tx/impl/MPTokenIssuanceSet.cpp +++ b/src/ripple/app/tx/impl/MPTokenIssuanceSet.cpp @@ -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 @@ -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; } diff --git a/src/ripple/protocol/impl/LedgerFormats.cpp b/src/ripple/protocol/impl/LedgerFormats.cpp index 1c95b161c2f..c20af507cf2 100644 --- a/src/ripple/protocol/impl/LedgerFormats.cpp +++ b/src/ripple/protocol/impl/LedgerFormats.cpp @@ -363,7 +363,7 @@ LedgerFormats::LedgerFormats() { {sfAccount, soeREQUIRED}, {sfMPTokenIssuanceID, soeREQUIRED}, - {sfMPTAmount, soeREQUIRED}, + {sfMPTAmount, soeDEFAULT}, {sfLockedAmount, soeDEFAULT}, {sfOwnerNode, soeREQUIRED}, {sfMPTokenNode, soeREQUIRED}, diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index 0bb943a5cab..0a7728d3847 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -25,6 +25,7 @@ namespace ripple { class MPToken_test : public beast::unit_test::suite { + [[nodiscard]] bool checkMPTokenAmount( test::jtx::Env const& env, @@ -40,6 +41,7 @@ class MPToken_test : public beast::unit_test::suite return amount == expectedAmount; } + [[nodiscard]] bool checkMPTokenIssuanceFlags( test::jtx::Env const& env, @@ -54,6 +56,7 @@ class MPToken_test : public beast::unit_test::suite return expectedFlags == mptIssuanceFlags; } + [[nodiscard]] bool checkMPTokenFlags( test::jtx::Env const& env, From fd444d0a48aa4738a177c8a93c8049a8cd202e5f Mon Sep 17 00:00:00 2001 From: Shawn Xie Date: Thu, 4 Jan 2024 15:36:37 -0500 Subject: [PATCH 2/2] clang --- src/ripple/app/tx/impl/MPTokenAuthorize.cpp | 3 +-- src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp | 6 +----- src/test/app/MPToken_test.cpp | 9 +++------ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/ripple/app/tx/impl/MPTokenAuthorize.cpp b/src/ripple/app/tx/impl/MPTokenAuthorize.cpp index 8bfde47c74b..529aa0499d2 100644 --- a/src/ripple/app/tx/impl/MPTokenAuthorize.cpp +++ b/src/ripple/app/tx/impl/MPTokenAuthorize.cpp @@ -189,8 +189,7 @@ MPTokenAuthorize::doApply() false)) return tecINTERNAL; - adjustOwnerCount( - view(), sleAcct, -1, j_); + adjustOwnerCount(view(), sleAcct, -1, j_); view().erase(sleMpt); return tesSUCCESS; diff --git a/src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp b/src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp index a1cd4dcd50c..60e0e77a933 100644 --- a/src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp +++ b/src/ripple/app/tx/impl/MPTokenIssuanceDestroy.cpp @@ -74,11 +74,7 @@ MPTokenIssuanceDestroy::doApply() view().erase(mpt); - adjustOwnerCount( - view(), - view().peek(keylet::account(issuer)), - -1, - j_); + adjustOwnerCount(view(), view().peek(keylet::account(issuer)), -1, j_); return tesSUCCESS; } diff --git a/src/test/app/MPToken_test.cpp b/src/test/app/MPToken_test.cpp index 0a7728d3847..4ccd4068bbb 100644 --- a/src/test/app/MPToken_test.cpp +++ b/src/test/app/MPToken_test.cpp @@ -25,8 +25,7 @@ namespace ripple { class MPToken_test : public beast::unit_test::suite { - [[nodiscard]] - bool + [[nodiscard]] bool checkMPTokenAmount( test::jtx::Env const& env, ripple::uint256 const mptIssuanceid, @@ -41,8 +40,7 @@ class MPToken_test : public beast::unit_test::suite return amount == expectedAmount; } - [[nodiscard]] - bool + [[nodiscard]] bool checkMPTokenIssuanceFlags( test::jtx::Env const& env, ripple::uint256 const mptIssuanceid, @@ -56,8 +54,7 @@ class MPToken_test : public beast::unit_test::suite return expectedFlags == mptIssuanceFlags; } - [[nodiscard]] - bool + [[nodiscard]] bool checkMPTokenFlags( test::jtx::Env const& env, ripple::uint256 const mptIssuanceid,