From 1b12d9d7ed468935763a1cb9dff81bbfbdd98dcf Mon Sep 17 00:00:00 2001 From: Gregory Tsipenyuk Date: Mon, 5 Aug 2024 19:39:06 -0400 Subject: [PATCH] Consolidate errors. Remove redundant checks. --- include/xrpl/protocol/TER.h | 4 +--- src/libxrpl/protocol/TER.cpp | 2 -- src/xrpld/app/tx/detail/AMMCreate.cpp | 2 +- src/xrpld/app/tx/detail/AMMDeposit.cpp | 2 +- src/xrpld/app/tx/detail/AMMWithdraw.cpp | 2 +- src/xrpld/app/tx/detail/CreateCheck.cpp | 3 --- src/xrpld/app/tx/detail/CreateOffer.cpp | 4 ---- src/xrpld/app/tx/detail/NFTokenCreateOffer.cpp | 2 +- src/xrpld/app/tx/detail/NFTokenMint.cpp | 2 +- src/xrpld/app/tx/detail/Payment.cpp | 15 +++++++++------ src/xrpld/app/tx/detail/XChainBridge.cpp | 15 +++++---------- 11 files changed, 20 insertions(+), 33 deletions(-) diff --git a/include/xrpl/protocol/TER.h b/include/xrpl/protocol/TER.h index 6d666a3fb55..afc915bc0a3 100644 --- a/include/xrpl/protocol/TER.h +++ b/include/xrpl/protocol/TER.h @@ -139,9 +139,7 @@ enum TEMcodes : TERUnderlyingType { temEMPTY_DID, temARRAY_EMPTY, - temARRAY_TOO_LARGE, - temMPT_NOT_SUPPORTED, - temMPT_INVALID_USAGE + temARRAY_TOO_LARGE }; //------------------------------------------------------------------------------ diff --git a/src/libxrpl/protocol/TER.cpp b/src/libxrpl/protocol/TER.cpp index 38842c34758..795ab74ca7d 100644 --- a/src/libxrpl/protocol/TER.cpp +++ b/src/libxrpl/protocol/TER.cpp @@ -189,8 +189,6 @@ transResults() MAKE_ERROR(temEMPTY_DID, "Malformed: No DID data provided."), MAKE_ERROR(temINVALID, "The transaction is ill-formed."), MAKE_ERROR(temINVALID_FLAG, "The transaction has an invalid flag."), - MAKE_ERROR(temMPT_NOT_SUPPORTED, "MPT is not supported."), - MAKE_ERROR(temMPT_INVALID_USAGE, "Invalid MPT usage."), MAKE_ERROR(temREDUNDANT, "The transaction is redundant."), MAKE_ERROR(temRIPPLE_EMPTY, "PathSet with no paths."), MAKE_ERROR(temUNCERTAIN, "In process of determining result. Never returned."), diff --git a/src/xrpld/app/tx/detail/AMMCreate.cpp b/src/xrpld/app/tx/detail/AMMCreate.cpp index 35c4563e4d3..12fee14e6ec 100644 --- a/src/xrpld/app/tx/detail/AMMCreate.cpp +++ b/src/xrpld/app/tx/detail/AMMCreate.cpp @@ -42,7 +42,7 @@ AMMCreate::preflight(PreflightContext const& ctx) return ret; if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfAmount])) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; if (ctx.tx.getFlags() & tfUniversalMask) { diff --git a/src/xrpld/app/tx/detail/AMMDeposit.cpp b/src/xrpld/app/tx/detail/AMMDeposit.cpp index a83a0b101c0..be6f2303e52 100644 --- a/src/xrpld/app/tx/detail/AMMDeposit.cpp +++ b/src/xrpld/app/tx/detail/AMMDeposit.cpp @@ -42,7 +42,7 @@ AMMDeposit::preflight(PreflightContext const& ctx) return ret; if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[~sfAmount])) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; auto const flags = ctx.tx.getFlags(); if (flags & tfDepositMask) diff --git a/src/xrpld/app/tx/detail/AMMWithdraw.cpp b/src/xrpld/app/tx/detail/AMMWithdraw.cpp index c6a70584a01..110291e9ac7 100644 --- a/src/xrpld/app/tx/detail/AMMWithdraw.cpp +++ b/src/xrpld/app/tx/detail/AMMWithdraw.cpp @@ -42,7 +42,7 @@ AMMWithdraw::preflight(PreflightContext const& ctx) return ret; if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[~sfAmount])) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; auto const flags = ctx.tx.getFlags(); if (flags & tfWithdrawMask) diff --git a/src/xrpld/app/tx/detail/CreateCheck.cpp b/src/xrpld/app/tx/detail/CreateCheck.cpp index 2fa1f323339..3a278eed738 100644 --- a/src/xrpld/app/tx/detail/CreateCheck.cpp +++ b/src/xrpld/app/tx/detail/CreateCheck.cpp @@ -38,9 +38,6 @@ CreateCheck::preflight(PreflightContext const& ctx) if (!isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfSendMax])) - return temMPT_NOT_SUPPORTED; - if (ctx.tx.getFlags() & tfUniversalMask) { // There are no flags (other than universal) for CreateCheck yet. diff --git a/src/xrpld/app/tx/detail/CreateOffer.cpp b/src/xrpld/app/tx/detail/CreateOffer.cpp index 7a6a723bac8..2a5145594a1 100644 --- a/src/xrpld/app/tx/detail/CreateOffer.cpp +++ b/src/xrpld/app/tx/detail/CreateOffer.cpp @@ -45,10 +45,6 @@ CreateOffer::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - (isMPT(ctx.tx[sfTakerPays]) || isMPT(ctx.tx[sfTakerGets]))) - return temMPT_NOT_SUPPORTED; - auto& tx = ctx.tx; auto& j = ctx.j; diff --git a/src/xrpld/app/tx/detail/NFTokenCreateOffer.cpp b/src/xrpld/app/tx/detail/NFTokenCreateOffer.cpp index 0f42fadb316..4321253204d 100644 --- a/src/xrpld/app/tx/detail/NFTokenCreateOffer.cpp +++ b/src/xrpld/app/tx/detail/NFTokenCreateOffer.cpp @@ -37,7 +37,7 @@ NFTokenCreateOffer::preflight(PreflightContext const& ctx) return ret; if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfAmount])) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; auto const txFlags = ctx.tx.getFlags(); diff --git a/src/xrpld/app/tx/detail/NFTokenMint.cpp b/src/xrpld/app/tx/detail/NFTokenMint.cpp index 30834df70f0..bea1fee4b7e 100644 --- a/src/xrpld/app/tx/detail/NFTokenMint.cpp +++ b/src/xrpld/app/tx/detail/NFTokenMint.cpp @@ -54,7 +54,7 @@ NFTokenMint::preflight(PreflightContext const& ctx) return ret; if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[~sfAmount])) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; // Prior to fixRemoveNFTokenAutoTrustLine, transfer of an NFToken between // accounts allowed a TrustLine to be added to the issuer of that token diff --git a/src/xrpld/app/tx/detail/Payment.cpp b/src/xrpld/app/tx/detail/Payment.cpp index ea18e79e935..5e9293c164f 100644 --- a/src/xrpld/app/tx/detail/Payment.cpp +++ b/src/xrpld/app/tx/detail/Payment.cpp @@ -185,14 +185,17 @@ preflightHelper(PreflightContext const& ctx) JLOG(j.trace()) << "Malformed transaction: " << "Paths specified for XRP to XRP or MPT to MPT."; if (bMPTDirect) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; return temBAD_SEND_XRP_PATHS; } - if (bXRPDirect && partialPaymentAllowed) + if (bDirect && partialPaymentAllowed) { // Consistent but redundant transaction. - JLOG(j.trace()) << "Malformed transaction: " - << "Partial payment specified for XRP to XRP."; + JLOG(j.trace()) + << "Malformed transaction: " + << "Partial payment specified for XRP to XRP or MPT to MPT."; + if (bMPTDirect) + return temMALFORMED; return temBAD_SEND_XRP_PARTIAL; } if (bDirect && limitQuality) @@ -202,7 +205,7 @@ preflightHelper(PreflightContext const& ctx) << "Malformed transaction: " << "Limit quality specified for XRP to XRP or MPT to MPT."; if (bMPTDirect) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; return temBAD_SEND_XRP_LIMIT; } if (bDirect && !defaultPathsAllowed) @@ -212,7 +215,7 @@ preflightHelper(PreflightContext const& ctx) << "Malformed transaction: " << "No ripple direct specified for XRP to XRP or MPT to MPT."; if (bMPTDirect) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; return temBAD_SEND_XRP_NO_DIRECT; } diff --git a/src/xrpld/app/tx/detail/XChainBridge.cpp b/src/xrpld/app/tx/detail/XChainBridge.cpp index e7f0253e462..f611aed7d48 100644 --- a/src/xrpld/app/tx/detail/XChainBridge.cpp +++ b/src/xrpld/app/tx/detail/XChainBridge.cpp @@ -1215,7 +1215,7 @@ attestationPreflight(PreflightContext const& ctx) return ret; if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfAmount])) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; if (ctx.tx.getFlags() & tfUniversalMask) return temINVALID_FLAG; @@ -1676,7 +1676,7 @@ XChainClaim::preflight(PreflightContext const& ctx) return ret; if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfAmount])) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; if (ctx.tx.getFlags() & tfUniversalMask) return temINVALID_FLAG; @@ -1917,7 +1917,7 @@ XChainCommit::preflight(PreflightContext const& ctx) return ret; if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfAmount])) - return temMPT_NOT_SUPPORTED; + return temMALFORMED; if (ctx.tx.getFlags() & tfUniversalMask) return temINVALID_FLAG; @@ -2035,10 +2035,6 @@ XChainCreateClaimID::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - isMPT(ctx.tx[sfSignatureReward])) - return temMPT_NOT_SUPPORTED; - if (ctx.tx.getFlags() & tfUniversalMask) return temINVALID_FLAG; @@ -2194,9 +2190,8 @@ XChainCreateAccountCommit::preflight(PreflightContext const& ctx) if (auto const ret = preflight1(ctx); !isTesSuccess(ret)) return ret; - if (ctx.rules.enabled(featureMPTokensV1) && - (isMPT(ctx.tx[sfAmount]) || isMPT(ctx.tx[sfSignatureReward]))) - return temMPT_NOT_SUPPORTED; + if (ctx.rules.enabled(featureMPTokensV1) && isMPT(ctx.tx[sfAmount])) + return temMALFORMED; if (ctx.tx.getFlags() & tfUniversalMask) return temINVALID_FLAG;