From e4009c8661bcf071f1a1dfd46f0b457fa42e08fa Mon Sep 17 00:00:00 2001 From: Shawn Xie <35279399+shawnxie999@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:51:03 -0400 Subject: [PATCH] address comments (#44) --- src/xrpld/app/tx/detail/MPTokenAuthorize.cpp | 21 ++++++++++++++----- src/xrpld/app/tx/detail/MPTokenAuthorize.h | 2 +- .../app/tx/detail/MPTokenIssuanceCreate.cpp | 4 ++-- .../app/tx/detail/MPTokenIssuanceDestroy.cpp | 12 ++++++----- .../app/tx/detail/MPTokenIssuanceDestroy.h | 4 ++-- .../app/tx/detail/MPTokenIssuanceSet.cpp | 4 ++-- src/xrpld/app/tx/detail/MPTokenIssuanceSet.h | 2 +- 7 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/xrpld/app/tx/detail/MPTokenAuthorize.cpp b/src/xrpld/app/tx/detail/MPTokenAuthorize.cpp index 7aea2020a47..0ad9252cb6d 100644 --- a/src/xrpld/app/tx/detail/MPTokenAuthorize.cpp +++ b/src/xrpld/app/tx/detail/MPTokenAuthorize.cpp @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2023 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -63,9 +63,11 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx) std::shared_ptr sleMpt = ctx.view.read( keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], accountID)); - // There is an edge case where holder deletes MPT after issuance has - // already been destroyed. So we must check for unauthorize before - // fetching the MPTIssuance object(since it doesn't exist) + // There is an edge case where all holders have zero balance, issuance + // is legally destroyed, then outstanding MPT(s) are deleted afterwards. + // Thus, there is no need to check for the existence of the issuance if + // the MPT is being deleted with a zero balance. Check for unauthorize + // before fetching the MPTIssuance object. // if holder wants to delete/unauthorize a mpt if (ctx.tx.getFlags() & tfMPTUnauthorize) @@ -74,7 +76,15 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx) return tecOBJECT_NOT_FOUND; if ((*sleMpt)[sfMPTAmount] != 0) + { + auto const sleMptIssuance = ctx.view.read( + keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID])); + assert(sleMptIssuance); + if (!sleMptIssuance) + return tefINTERNAL; + return tecHAS_OBLIGATIONS; + } return tesSUCCESS; } @@ -118,6 +128,7 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx) if (!(mptIssuanceFlags & lsfMPTRequireAuth)) return tecNO_AUTH; + // The holder must create the MPT before the issuer can authorize it. if (!ctx.view.exists( keylet::mptoken(ctx.tx[sfMPTokenIssuanceID], *holderID))) return tecOBJECT_NOT_FOUND; @@ -148,7 +159,7 @@ MPTokenAuthorize::authorize( auto const mptokenKey = keylet::mptoken(args.mptIssuanceID, args.account); auto const sleMpt = view.peek(mptokenKey); - if (!sleMpt) + if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0) return tecINTERNAL; if (!view.dirRemove( diff --git a/src/xrpld/app/tx/detail/MPTokenAuthorize.h b/src/xrpld/app/tx/detail/MPTokenAuthorize.h index 94451a61c88..79dc1734b5b 100644 --- a/src/xrpld/app/tx/detail/MPTokenAuthorize.h +++ b/src/xrpld/app/tx/detail/MPTokenAuthorize.h @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2023 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp b/src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp index a164584aa81..1297a918e1d 100644 --- a/src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp +++ b/src/xrpld/app/tx/detail/MPTokenIssuanceCreate.cpp @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2023 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -55,7 +55,7 @@ MPTokenIssuanceCreate::preflight(PreflightContext const& ctx) return temMALFORMED; } - // Check if maximumAmount is within 63 bit range + // Check if maximumAmount is within unsigned 63 bit range if (auto const maxAmt = ctx.tx[~sfMaximumAmount]) { if (maxAmt == 0) diff --git a/src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.cpp b/src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.cpp index 4eb6225c0b4..a0f0b9d8602 100644 --- a/src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.cpp +++ b/src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.cpp @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2023 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -18,6 +18,7 @@ //============================================================================== #include + #include #include #include @@ -66,17 +67,18 @@ MPTokenIssuanceDestroy::doApply() { auto const mpt = view().peek(keylet::mptIssuance(ctx_.tx[sfMPTokenIssuanceID])); - auto const issuer = (*mpt)[sfIssuer]; + if (account_ != mpt->getAccountID(sfIssuer)) + return tecINTERNAL; if (!view().dirRemove( - keylet::ownerDir(issuer), (*mpt)[sfOwnerNode], mpt->key(), false)) + keylet::ownerDir(account_), (*mpt)[sfOwnerNode], mpt->key(), false)) return tefBAD_LEDGER; view().erase(mpt); - adjustOwnerCount(view(), view().peek(keylet::account(issuer)), -1, j_); + adjustOwnerCount(view(), view().peek(keylet::account(account_)), -1, j_); return tesSUCCESS; } -} // namespace ripple \ No newline at end of file +} // namespace ripple diff --git a/src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.h b/src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.h index 3e9f9b7e5cf..69abb99feb0 100644 --- a/src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.h +++ b/src/xrpld/app/tx/detail/MPTokenIssuanceDestroy.h @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2023 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -45,4 +45,4 @@ class MPTokenIssuanceDestroy : public Transactor } // namespace ripple -#endif \ No newline at end of file +#endif diff --git a/src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp b/src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp index 2b4ff2bcb8a..352fa674cb8 100644 --- a/src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp +++ b/src/xrpld/app/tx/detail/MPTokenIssuanceSet.cpp @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2023 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -115,4 +115,4 @@ MPTokenIssuanceSet::doApply() return tesSUCCESS; } -} // namespace ripple \ No newline at end of file +} // namespace ripple diff --git a/src/xrpld/app/tx/detail/MPTokenIssuanceSet.h b/src/xrpld/app/tx/detail/MPTokenIssuanceSet.h index 36080d46667..895be973120 100644 --- a/src/xrpld/app/tx/detail/MPTokenIssuanceSet.h +++ b/src/xrpld/app/tx/detail/MPTokenIssuanceSet.h @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ /* This file is part of rippled: https://github.com/ripple/rippled - Copyright (c) 2023 Ripple Labs Inc. + Copyright (c) 2024 Ripple Labs Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above