diff --git a/include/xrpl/protocol/Asset.h b/include/xrpl/protocol/Asset.h index bfb72ab61fc..54c030d7d8a 100644 --- a/include/xrpl/protocol/Asset.h +++ b/include/xrpl/protocol/Asset.h @@ -97,6 +97,13 @@ class Asset friend constexpr bool operator==(Currency const& lhs, Asset const& rhs); + + /** Return true if both asset's issue (Issue or MPTIssue) + * are the same and hold the same token (currency or MPTID). + * Otherwise return false. + */ + friend constexpr bool + equalTokens(Asset const& lhs, Asset const& rhs); }; template @@ -157,6 +164,26 @@ operator==(Currency const& lhs, Asset const& rhs) return rhs.holds() && rhs.get().currency == lhs; } +constexpr bool +equalTokens(Asset const& lhs, Asset const& rhs) +{ + return std::visit( + [&]( + TLhs const& issLhs, TRhs const& issRhs) { + if constexpr ( + std::is_same_v && std::is_same_v) + return issLhs.currency == issRhs.currency; + else if constexpr ( + std::is_same_v && + std::is_same_v) + return issLhs.getMptID() == issRhs.getMptID(); + else + return false; + }, + lhs.issue_, + rhs.issue_); +} + inline bool isXRP(Asset const& asset) { diff --git a/src/xrpld/app/tx/detail/Payment.cpp b/src/xrpld/app/tx/detail/Payment.cpp index 25ec119d6ae..77c8d015d1e 100644 --- a/src/xrpld/app/tx/detail/Payment.cpp +++ b/src/xrpld/app/tx/detail/Payment.cpp @@ -145,7 +145,7 @@ Payment::preflight(PreflightContext const& ctx) JLOG(j.trace()) << "Malformed transaction: " << "Bad currency."; return temBAD_CURRENCY; } - if (account == dstAccountID && srcAsset == dstAsset && !hasPaths) + if (account == dstAccountID && equalTokens(srcAsset, dstAsset) && !hasPaths) { // You're signing yourself a payment. // If hasPaths is true, you might be trying some arbitrage.