Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/xrpl/ledger/entries/MPTokenIssuanceEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ class MPTokenIssuanceEntry : public SLEBase<ViewT, ltMPTOKEN_ISSUANCE>
{
return this->sleRef().isFlag(lsfMPTLocked);
}

/**
* Returns the issuance's MaximumAmount, or the protocol maximum if the
* field is absent. Never exceeds 2**63-1.
*
* @return the maximum amount that may be outstanding for this issuance.
*/
[[nodiscard]] std::int64_t
maxAmount() const;
};

using MPTokenIssuanceEntryR = MPTokenIssuanceEntry<ReadView>;
Expand Down
21 changes: 21 additions & 0 deletions src/libxrpl/ledger/entries/MPTokenIssuanceEntry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <xrpl/ledger/entries/MPTokenIssuanceEntry.h>

#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/helpers/MPTokenHelpers.h>

#include <cstdint>

namespace xrpl {

template <typename ViewT>
std::int64_t
MPTokenIssuanceEntry<ViewT>::maxAmount() const
{
return maxMPTAmount(this->sleRef());
}

template class MPTokenIssuanceEntry<ReadView>;
template class MPTokenIssuanceEntry<ApplyView>;

} // namespace xrpl
2 changes: 1 addition & 1 deletion src/libxrpl/ledger/helpers/MPTokenHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ maxMPTAmount(ReadView const& view, MPTID const& mptID)
std::int64_t
availableMPTAmount(MPTokenIssuanceEntryR const& sleIssuance)
{
auto const max = maxMPTAmount(*sleIssuance);
auto const max = sleIssuance.maxAmount();
auto const outstanding = (*sleIssuance)[sfOutstandingAmount];
return max - outstanding;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libxrpl/ledger/helpers/TokenHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ directSendNoFeeMPT(
if (!sleIssuance)
return tecOBJECT_NOT_FOUND;

auto const maxAmount = maxMPTAmount(*sleIssuance);
auto const maxAmount = sleIssuance.maxAmount();
auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount);
auto const available = availableMPTAmount(sleIssuance);
auto const amt = saAmount.mpt().value();
Expand Down Expand Up @@ -1335,7 +1335,7 @@ directSendNoLimitMPT(
if (uSenderID == issuer)
{
auto const sendAmount = saAmount.mpt().value();
auto const maxAmount = maxMPTAmount(*sle);
auto const maxAmount = sle.maxAmount();
auto const outstanding = sle->getFieldU64(sfOutstandingAmount);
auto const mptokensV2 = view.rules().enabled(featureMPTokensV2);
allowOverflow = (allowOverflow == AllowMPTOverflow::Yes && mptokensV2)
Expand Down
2 changes: 1 addition & 1 deletion src/libxrpl/tx/paths/MPTEndpointStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ MPTEndpointStep<TDerived>::maxPaymentFlow(ReadView const& sb) const
// the previous step may issue or redeem. Allow OutstandingAmount
// to temporarily overflow. Let the previous step figure out how
// to limit the flow.
std::int64_t const maxAmount = maxMPTAmount(*sle);
std::int64_t const maxAmount = sle.maxAmount();
return {MPTAmount{maxAmount}, DebtDirection::Issues};
}

Expand Down
Loading