Skip to content

Commit

Permalink
Refactor Payment and Clawback transactors
Browse files Browse the repository at this point in the history
to have separate functions for MPT/IOU
handling since there is little overlap
between them.
  • Loading branch information
gregtatcam committed Aug 15, 2024
1 parent 39e8906 commit fe8e9d2
Show file tree
Hide file tree
Showing 7 changed files with 570 additions and 487 deletions.
1 change: 0 additions & 1 deletion include/xrpl/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,6 @@ extern SField const sfXChainClaimProofSig;
extern SField const sfXChainCreateAccountProofSig;
extern SField const sfXChainClaimAttestationCollectionElement;
extern SField const sfXChainCreateAccountAttestationCollectionElement;
extern SField const MPToken;

// array of objects (common)
// ARRAY/1 is reserved for end of array
Expand Down
6 changes: 6 additions & 0 deletions include/xrpl/protocol/STAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ STAmount::value() const noexcept
return *this;
}

inline bool
isLegalNet(STAmount const& value)
{
return !value.native() || (value.mantissa() <= STAmount::cMaxNativeN);
}

//------------------------------------------------------------------------------
//
// Operators
Expand Down
41 changes: 0 additions & 41 deletions include/xrpl/protocol/STEitherAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,47 +213,6 @@ operator!=(STEitherAmount const& lhs, STEitherAmount const& rhs)
return !operator==(lhs, rhs);
}

template <ValidAssetType T1, ValidAssetType T2>
bool
sameAsset(T1 const& t1, T2 const& t2)
{
if constexpr (std::is_same_v<T1, T2>)
return t1 == t2;
else
return false;
}

template <ValidAssetType T>
bool
badAsset(T const& t)
{
if constexpr (std::is_same_v<T, Currency>)
return badCurrency() == t;
else
return badMPT() == t;
}

inline bool
isLegalNet(STEitherAmount const& value)
{
if (value.isIssue())
{
auto const& v = get<STAmount>(value);
return !v.native() || (v.mantissa() <= STAmount::cMaxNativeN);
}
return true;
}

template <ValidAmountType T>
bool
isNative(T const& amount)
{
if constexpr (std::is_same_v<T, STMPTAmount>)
return false;
else if constexpr (std::is_same_v<T, STAmount>)
return amount.native();
}

template <ValidAmountType T>
bool
isMPT(T const& amount)
Expand Down
6 changes: 6 additions & 0 deletions include/xrpl/protocol/STMPTAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ operator>=(STMPTAmount const& lhs, STMPTAmount const& rhs)
return !(lhs < rhs);
}

inline bool
isLegalNet(STMPTAmount const& value)
{
return true;
}

STMPTAmount
amountFromString(MPTIssue const& issue, std::string const& amount);

Expand Down
2 changes: 1 addition & 1 deletion src/test/app/MPToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ class MPToken_test : public beast::unit_test::suite
auto const mpt = ripple::test::jtx::MPT(
alice.name(), std::make_pair(env.seq(alice), alice.id()));

env(claw(alice, bob["USD"](5), bob), ter(temDISABLED));
env(claw(alice, bob["USD"](5), bob), ter(temMALFORMED));
env.close();

env(claw(alice, mpt(5)), ter(temDISABLED));
Expand Down
Loading

0 comments on commit fe8e9d2

Please sign in to comment.