Fix token comparison in Payment (#5172)

* Checks only Currency or MPT Issuance ID part of the Asset object.
* Resolves temREDUNDANT regression detected in testing.
This commit is contained in:
Gregory Tsipenyuk
2024-11-06 11:20:30 -05:00
committed by GitHub
parent ec61f5e9d3
commit c5c0e70e23
4 changed files with 169 additions and 1 deletions

View File

@@ -97,6 +97,12 @@ public:
friend constexpr bool
operator==(Currency const& lhs, Asset const& rhs);
/** Return true if both assets refer to the same currency (regardless of
* issuer) or MPT issuance. Otherwise return false.
*/
friend constexpr bool
equalTokens(Asset const& lhs, Asset const& rhs);
};
template <ValidIssueType TIss>
@@ -157,6 +163,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)
{
@@ -172,6 +198,9 @@ validJSONAsset(Json::Value const& jv);
Asset
assetFromJson(Json::Value const& jv);
Json::Value
to_json(Asset const& asset);
} // namespace ripple
#endif // RIPPLE_PROTOCOL_ASSET_H_INCLUDED