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>
16template <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.";
80 !sleDest->isFlag(lsfDefaultRipple),
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 !=
kParityRate)
120 finalAmt = amount.
value() - xferFee;
127 auto const sleRippleState = view.
peek(trustLineKey);
134 sleRippleState->getFieldAmount(recvLow ? sfLowLimit : sfHighLimit);
136 STAmount lineBalance = sleRippleState->getFieldAmount(sfBalance);
143 lineBalance += finalAmt;
146 if (lineLimit < lineBalance)
153 auto const ter =
directSendNoFee(view, issuer, receiver, finalAmt,
true, journal);
174 bool const senderIssuer = issuer == sender;
175 bool const receiverIssuer = issuer == receiver;
177 auto const mptID = amount.
get<
MPTIssue>().getMptID();
181 if (
std::uint32_t const ownerCount = {sleDest->at(sfOwnerCount)};
182 xrpBalance < view.
fees().accountReserve(ownerCount + 1))
201 if (xferRate < lockedRate)
202 lockedRate = xferRate;
213 auto finalAmt = amount;
214 if ((!senderIssuer && !receiverIssuer) && lockedRate !=
kParityRate)
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 SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void update(SLE::ref sle)=0
Indicate changes to a peeked SLE.
A currency issued by an account.
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.
constexpr TIss const & get() const
Asset const & asset() const
STAmount const & value() const noexcept
std::shared_ptr< STLedgerEntry > const & ref
Keylet mptokenIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet trustLine(AccountID const &id0, AccountID const &id1, Currency const ¤cy) noexcept
The index of a trust line for a given currency.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TER escrowUnlockApplyHelper(ApplyView &view, Rate lockedRate, SLE::ref sleDest, STAmount const &xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
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.
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
TER unlockEscrowMPT(ApplyView &view, AccountID const &uGrantorID, AccountID const &uGranteeID, STAmount const &netAmount, STAmount const &grossAmount, beast::Journal j)
TER createMPToken(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, std::uint32_t const flags)
Rate transferRate(ReadView const &view, AccountID const &issuer)
Returns IOU issuer transfer fee as Rate.
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
TER directSendNoFee(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, bool bCheckIssuer, beast::Journal j)
Calls static directSendNoFeeIOU if saAmount represents Issue.
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
TER escrowUnlockApplyHelper< MPTIssue >(ApplyView &view, Rate lockedRate, SLE::ref sleDest, STAmount const &xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
AccountID const & noAccount()
A placeholder for empty accounts.
TER escrowUnlockApplyHelper< Issue >(ApplyView &view, Rate lockedRate, SLE::ref sleDest, STAmount const &xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
@ tecNO_LINE_INSUF_RESERVE
@ tecINSUFFICIENT_RESERVE
STAmount divideRound(STAmount const &amount, Rate const &rate, bool roundUp)
A pair of SHAMap key and LedgerEntryType.
Represents a transfer rate.