Skip to content

Commit

Permalink
Fix tokens comparison in Payment for temREDUNDANT error
Browse files Browse the repository at this point in the history
  • Loading branch information
gregtatcam committed Oct 31, 2024
1 parent 0d887ad commit 122ee8b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions include/xrpl/protocol/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ValidIssueType TIss>
Expand Down Expand Up @@ -157,6 +164,26 @@ operator==(Currency const& lhs, Asset const& rhs)
return rhs.holds<Issue>() && rhs.get<Issue>().currency == lhs;
}

constexpr bool
equalTokens(Asset const& lhs, Asset const& rhs)
{
return std::visit(
[&]<typename TLhs, typename TRhs>(
TLhs const& issLhs, TRhs const& issRhs) {
if constexpr (
std::is_same_v<TLhs, Issue> && std::is_same_v<TRhs, Issue>)
return issLhs.currency == issRhs.currency;
else if constexpr (
std::is_same_v<TLhs, MPTIssue> &&
std::is_same_v<TRhs, MPTIssue>)
return issLhs.getMptID() == issRhs.getMptID();
else
return false;
},
lhs.issue_,
rhs.issue_);
}

inline bool
isXRP(Asset const& asset)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/tx/detail/Payment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 122ee8b

Please sign in to comment.