3#include <xrpl/basics/Log.h>
4#include <xrpl/ledger/ApplyView.h>
5#include <xrpl/ledger/View.h>
6#include <xrpl/ledger/helpers/AccountRootHelpers.h>
7#include <xrpl/ledger/helpers/MPTokenHelpers.h>
8#include <xrpl/ledger/helpers/RippleStateHelpers.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/MPTAmount.h>
12#include <xrpl/protocol/Rate.h>
13#include <xrpl/tx/transactors/token/MPTokenAuthorize.h>
17template <Val
idIssueType T>
46 bool const recvLow = issuer > receiver;
47 bool const senderIssuer = issuer == sender;
48 bool const receiverIssuer = issuer == receiver;
56 if (!view.
exists(trustLineKey) && createAsset)
59 if (
std::uint32_t const ownerCount = {sleDest->at(sfOwnerCount)};
60 xrpBalance < view.
fees().accountReserve(ownerCount + 1))
62 JLOG(journal.
trace()) <<
"Trust line does not exist. "
63 "Insufficient reserve to create line.";
68 Currency const currency = amount.getCurrency();
69 STAmount initialBalance(amount.issue());
80 (sleDest->getFlags() & lsfDefaultRipple) == 0,
84 Issue(currency, receiver),
96 if (!view.
exists(trustLineKey) && !receiverIssuer)
101 if (xferRate < lockedRate)
102 lockedRate = xferRate;
113 auto finalAmt = amount;
114 if ((!senderIssuer && !receiverIssuer) && lockedRate !=
parityRate)
117 auto const xferFee = amount.value() -
divideRound(amount, lockedRate, amount.issue(),
true);
119 finalAmt = amount.value() - xferFee;
126 auto const sleRippleState = view.
peek(trustLineKey);
133 sleRippleState->getFieldAmount(recvLow ? sfLowLimit : sfHighLimit);
135 STAmount lineBalance = sleRippleState->getFieldAmount(sfBalance);
142 lineBalance += finalAmt;
145 if (lineLimit < lineBalance)
152 auto const ter =
rippleCredit(view, issuer, receiver, finalAmt,
true, journal);
173 bool const senderIssuer = issuer == sender;
174 bool const receiverIssuer = issuer == receiver;
176 auto const mptID = amount.get<
MPTIssue>().getMptID();
180 if (
std::uint32_t const ownerCount = {sleDest->at(sfOwnerCount)};
181 xrpBalance < view.
fees().accountReserve(ownerCount + 1))
201 if (xferRate < lockedRate)
202 lockedRate = xferRate;
213 auto finalAmt = amount;
214 if ((!senderIssuer && !receiverIssuer) && lockedRate !=
parityRate)
217 auto const xferFee = amount.value() -
divideRound(amount, lockedRate, amount.asset(),
true);
219 finalAmt = amount.value() - xferFee;
226 view.
rules().
enabled(fixTokenEscrowV1) ? amount : finalAmt,
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
Writeable view to a ledger, for applying a transaction.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
A currency issued by an account.
static TER createMPToken(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, std::uint32_t const flags)
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
void setIssuer(AccountID const &uIssuer)
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
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TER rippleUnlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER trustCreate(ApplyView &view, bool const bSrcHigh, AccountID const &uSrcAccountID, AccountID const &uDstAccountID, uint256 const &uIndex, SLE::ref sleAccount, bool const bAuth, bool const bNoRipple, bool const bFreeze, bool bDeepFreeze, STAmount const &saBalance, STAmount const &saLimit, std::uint32_t uQualityIn, std::uint32_t uQualityOut, beast::Journal j)
Create a trust line.
TER escrowUnlockApplyHelper< MPTIssue >(ApplyView &view, Rate lockedRate, std::shared_ptr< SLE > const &sleDest, STAmount const &xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
TERSubset< CanCvtToTER > TER
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
TER escrowUnlockApplyHelper(ApplyView &view, Rate lockedRate, std::shared_ptr< SLE > const &sleDest, STAmount const &xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
AccountID const & noAccount()
A placeholder for empty accounts.
bool isTesSuccess(TER x) noexcept
TER escrowUnlockApplyHelper< Issue >(ApplyView &view, Rate lockedRate, std::shared_ptr< SLE > const &sleDest, STAmount const &xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
@ tecNO_LINE_INSUF_RESERVE
@ tecINSUFFICIENT_RESERVE
STAmount divideRound(STAmount const &amount, Rate const &rate, bool roundUp)
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
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.
A pair of SHAMap key and LedgerEntryType.
Represents a transfer rate.