Skip to content

Commit

Permalink
Combine Issue/MPTIssue handling in Payment transactor plus other changes
Browse files Browse the repository at this point in the history
* Add support for DeliverMin and partial payment
* Fix error for non-existent issuance payment
* Update unit-tests
* Refactor unit-test for tx with non-MPT amounts
  • Loading branch information
gregtatcam committed Oct 9, 2024
1 parent 560cf91 commit 6a7a8c2
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 371 deletions.
9 changes: 9 additions & 0 deletions include/xrpl/protocol/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class Asset

friend constexpr bool
operator!=(Asset const& lhs, Asset const& rhs);

friend constexpr bool
operator==(Currency const& lhs, Asset const& rhs);
};

template <ValidIssueType TIss>
Expand Down Expand Up @@ -148,6 +151,12 @@ operator!=(Asset const& lhs, Asset const& rhs)
return !(lhs == rhs);
}

constexpr bool
operator==(Currency const& lhs, Asset const& rhs)
{
return rhs.holds<Issue>() && rhs.get<Issue>().currency == lhs;
}

inline bool
isXRP(Asset const& asset)
{
Expand Down
2 changes: 2 additions & 0 deletions include/xrpl/protocol/MPTIssue.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ operator!=(MPTIssue const& lhs, MPTIssue const& rhs)
return !(lhs == rhs);
}

/** MPT is a non-native token.
*/
inline bool
isXRP(MPTID const&)
{
Expand Down
4 changes: 2 additions & 2 deletions include/xrpl/protocol/Rate.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ STAmount
multiplyRound(
STAmount const& amount,
Rate const& rate,
Issue const& issue,
Asset const& asset,
bool roundUp);

STAmount
Expand All @@ -87,7 +87,7 @@ STAmount
divideRound(
STAmount const& amount,
Rate const& rate,
Issue const& issue,
Asset const& issue,
bool roundUp);

namespace nft {
Expand Down
2 changes: 2 additions & 0 deletions src/libxrpl/protocol/MPTIssue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ MPTIssue::MPTIssue(MPTID const& issuanceID) : mptID_(issuanceID)
AccountID const&
MPTIssue::getIssuer() const
{
// MPTID is concatenation of sequence + account
static_assert(sizeof(MPTID) == (sizeof(std::uint32_t) + sizeof(AccountID)));
// copy from id skipping the sequence
AccountID const* account = reinterpret_cast<AccountID const*>(
mptID_.data() + sizeof(std::uint32_t));
Expand Down
12 changes: 6 additions & 6 deletions src/libxrpl/protocol/Rate2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ STAmount
multiplyRound(
STAmount const& amount,
Rate const& rate,
Issue const& issue,
Asset const& asset,
bool roundUp)
{
assert(rate.value != 0);
Expand All @@ -79,7 +79,7 @@ multiplyRound(
return amount;
}

return mulRound(amount, detail::as_amount(rate), issue, roundUp);
return mulRound(amount, detail::as_amount(rate), asset, roundUp);
}

STAmount
Expand All @@ -90,7 +90,7 @@ divide(STAmount const& amount, Rate const& rate)
if (rate == parityRate)
return amount;

return divide(amount, detail::as_amount(rate), amount.issue());
return divide(amount, detail::as_amount(rate), amount.asset());
}

STAmount
Expand All @@ -101,22 +101,22 @@ divideRound(STAmount const& amount, Rate const& rate, bool roundUp)
if (rate == parityRate)
return amount;

return divRound(amount, detail::as_amount(rate), amount.issue(), roundUp);
return divRound(amount, detail::as_amount(rate), amount.asset(), roundUp);
}

STAmount
divideRound(
STAmount const& amount,
Rate const& rate,
Issue const& issue,
Asset const& asset,
bool roundUp)
{
assert(rate.value != 0);

if (rate == parityRate)
return amount;

return divRound(amount, detail::as_amount(rate), issue, roundUp);
return divRound(amount, detail::as_amount(rate), asset, roundUp);
}

} // namespace ripple
2 changes: 1 addition & 1 deletion src/libxrpl/protocol/TxFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ TxFormats::TxFormats()
{sfPaths, soeDEFAULT},
{sfInvoiceID, soeOPTIONAL},
{sfDestinationTag, soeOPTIONAL},
{sfDeliverMin, soeOPTIONAL},
{sfDeliverMin, soeOPTIONAL, soeMPTSupported},
},
commonFields);

Expand Down
Loading

0 comments on commit 6a7a8c2

Please sign in to comment.