1#include <xrpl/ledger/View.h>
2#include <xrpl/ledger/helpers/AccountRootHelpers.h>
3#include <xrpl/ledger/helpers/TokenHelpers.h>
4#include <xrpl/protocol/Feature.h>
5#include <xrpl/protocol/Indexes.h>
6#include <xrpl/protocol/MPTAmount.h>
7#include <xrpl/protocol/Protocol.h>
8#include <xrpl/protocol/TxFlags.h>
9#include <xrpl/tx/transactors/token/Clawback.h>
13template <Val
idIssueType T>
30 if (issuer == holder ||
isXRP(clawAmount) || clawAmount <= beast::zero)
43 auto const mptHolder = ctx.
tx[~sfHolder];
44 auto const clawAmount = ctx.
tx[sfAmount];
50 if (ctx.
tx[sfAccount] == *mptHolder)
53 if (clawAmount.mpt() >
MPTAmount{maxMPTokenAmount} || clawAmount <= beast::zero)
63 [&]<
typename T>(T
const&) {
return preflightHelper<T>(ctx); },
64 ctx.
tx[sfAmount].asset().value());
71template <Val
idIssueType T>
93 if (((issuerFlagsIn & lsfAllowTrustLineClawback) == 0u) ||
94 ((issuerFlagsIn & lsfNoFreeze) != 0u))
97 auto const sleRippleState =
102 STAmount const balance = (*sleRippleState)[sfBalance];
105 if (balance > beast::zero && issuer < holder)
109 if (balance < beast::zero && issuer > holder)
132 SLE const& sleIssuer,
138 auto const sleIssuance = ctx.
view.
read(issuanceKey);
142 if (((*sleIssuance)[sfFlags] & lsfMPTCanClawback) == 0u)
145 if (sleIssuance->getAccountID(sfIssuer) != issuer)
163 auto const clawAmount = ctx.
tx[sfAmount];
168 if (!sleIssuer || !sleHolder)
177 if (sleHolder->isFieldPresent(sfAMMID))
183 [&]<
typename T>(T
const&) {
184 return preclaimHelper<T>(ctx, *sleIssuer, issuer, holder, clawAmount);
186 ctx.
tx[sfAmount].asset().value());
189template <Val
idIssueType T>
203 if (holder == issuer)
224 auto clawAmount = ctx.
tx[sfAmount];
240 std::min(spendableAmount, clawAmount),
249 [&]<
typename T>(T
const&) {
return applyHelper<T>(
ctx_); },
250 ctx_.
tx[sfAmount].asset().value());
State information when applying a tx.
beast::Journal const journal
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
A currency issued by an account.
AccountID const & getIssuer() const
constexpr MPTID const & getMptID() const
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
constexpr TIss const & get() const
void setIssuer(AccountID const &uIssuer)
Currency const & getCurrency() const
AccountID const & getIssuer() const
std::uint32_t getFieldU32(SField const &field) const
bool isFieldPresent(SField const &field) const
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet line(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isXRP(AccountID const &c)
static TER applyHelper(ApplyContext &ctx)
STAmount accountHolds(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer, FreezeHandling zeroIfFrozen, beast::Journal j, SpendableHandling includeFullBalance=shSIMPLE_BALANCE)
static NotTEC preflightHelper(PreflightContext const &ctx)
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct, std::set< SField const * > const &pseudoFieldFilter={})
Returns true if and only if sleAcct is a pseudo-account or specific pseudo-accounts in pseudoFieldFil...
TERSubset< CanCvtToTER > TER
TER preclaimHelper< Issue >(PreclaimContext const &ctx, SLE const &sleIssuer, STAmount const &clawAmount)
NotTEC preflightHelper< MPTIssue >(PreflightContext const &ctx)
NotTEC preflightHelper< Issue >(PreflightContext const &ctx)
bool isTesSuccess(TER x) noexcept
TER preclaimHelper< MPTIssue >(PreclaimContext const &ctx, SLE const &sleIssuer, STAmount const &clawAmount)
TER applyHelper< MPTIssue >(ApplyContext &ctx)
TER applyHelper< Issue >(ApplyContext &ctx)
TERSubset< CanCvtToNotTEC > NotTEC
static TER preclaimHelper(PreclaimContext const &ctx, SLE const &sleIssuer, STAmount const &clawAmount)
TER rippleCredit(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static rippleCreditIOU if saAmount represents Issue.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.