3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/ledger/ApplyView.h>
7#include <xrpl/ledger/helpers/AccountRootHelpers.h>
8#include <xrpl/ledger/helpers/MPTokenHelpers.h>
9#include <xrpl/ledger/helpers/RippleStateHelpers.h>
10#include <xrpl/ledger/helpers/SponsorHelpers.h>
11#include <xrpl/ledger/helpers/TokenHelpers.h>
12#include <xrpl/protocol/AccountID.h>
13#include <xrpl/protocol/Concepts.h>
14#include <xrpl/protocol/Feature.h>
15#include <xrpl/protocol/Indexes.h>
16#include <xrpl/protocol/Issue.h>
17#include <xrpl/protocol/Keylet.h>
18#include <xrpl/protocol/LedgerFormats.h>
19#include <xrpl/protocol/MPTAmount.h>
20#include <xrpl/protocol/MPTIssue.h>
21#include <xrpl/protocol/Rate.h>
22#include <xrpl/protocol/SField.h>
23#include <xrpl/protocol/STAmount.h>
24#include <xrpl/protocol/STLedgerEntry.h>
25#include <xrpl/protocol/TER.h>
26#include <xrpl/protocol/UintTypes.h>
30template <Val
idIssueType T>
58 auto const& issue = amount.
get<
Issue>();
60 bool const recvLow = issuer > receiver;
61 bool const senderIssuer = issuer == sender;
62 bool const receiverIssuer = issuer == receiver;
70 if (!ctx.
view.
exists(trustLineKey) && createAsset)
75 return sponsorSle.error();
82 {.ownerCountDelta = 1},
87 JLOG(journal.
trace()) <<
"Trust line does not exist. "
88 "Insufficient reserve to create line.";
92 Currency const currency = issue.currency;
104 !sleDest->isFlag(lsfDefaultRipple),
108 Issue(currency, receiver),
121 if (!ctx.
view.
exists(trustLineKey) && !receiverIssuer)
126 if (xferRate < lockedRate)
127 lockedRate = xferRate;
138 auto finalAmt = amount;
139 if ((!senderIssuer && !receiverIssuer) && lockedRate !=
kParityRate)
145 finalAmt = amount.
value() - xferFee;
152 auto const sleRippleState = ctx.
view.
peek(trustLineKey);
159 sleRippleState->getFieldAmount(recvLow ? sfLowLimit : sfHighLimit);
161 STAmount lineBalance = sleRippleState->getFieldAmount(sfBalance);
168 lineBalance += finalAmt;
171 if (lineLimit < lineBalance)
199 bool const senderIssuer = issuer == sender;
200 bool const receiverIssuer = issuer == receiver;
202 auto const mptID = amount.
get<
MPTIssue>().getMptID();
205 if (!ctx.
view.
exists(mptKeylet) && createAsset && !receiverIssuer)
209 return sponsorSle.error();
212 ctx, sleDest, xrpBalance, *sponsorSle, {.ownerCountDelta = 1}, journal);
226 if (!ctx.
view.
exists(mptKeylet) && !receiverIssuer)
231 if (xferRate < lockedRate)
232 lockedRate = xferRate;
243 auto finalAmt = amount;
244 if ((!senderIssuer && !receiverIssuer) && lockedRate !=
kParityRate)
250 "xrpl::escrowUnlockApplyHelper<MPTIssue> : lockedRate is at least parity");
253 auto const delivered =
263 finalAmt = amount.
value() - xferFee;
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
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.
constexpr value_type const & value() const
A currency issued by an account.
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.
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 mptoken(MPTID const &issuanceID, AccountID const &holder) noexcept
Keylet mptokenIssuance(MPTID const &issuanceID) 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 createMPToken(ApplyView &view, MPTID const &mptIssuanceID, AccountID const &account, SLE::ref sponsorSle, std::uint32_t const flags)
TER escrowUnlockApplyHelper< Issue >(ApplyViewContext ctx, Rate lockedRate, SLE::ref sleDest, XRPAmount xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
void increaseOwnerCount(ApplyView &view, SLE::ref accountSle, SLE::ref sponsorSle, std::uint32_t count, beast::Journal j)
Increase owner-count fields when the caller supplies the sponsor.
TER escrowUnlockApplyHelper(ApplyViewContext ctx, Rate lockedRate, SLE::ref sleDest, XRPAmount xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
TER escrowUnlockApplyHelper< MPTIssue >(ApplyViewContext ctx, Rate lockedRate, SLE::ref sleDest, XRPAmount xrpBalance, STAmount const &amount, AccountID const &issuer, AccountID const &sender, AccountID const &receiver, bool createAsset, beast::Journal journal)
TER unlockEscrowMPT(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, SLE::ref sponsorSle, beast::Journal j)
Create a trust line.
std::expected< SLE::pointer, TER > getEffectiveTxReserveSponsor(ApplyViewContext ctx, SLE::const_ref accountSle)
The transaction's reserve sponsor for the given account, if applicable.
IOUAmount mulRatio(IOUAmount const &amt, std::uint32_t num, std::uint32_t den, bool roundUp)
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.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
AccountID const & noAccount()
A placeholder for empty accounts.
TER checkReserve(ApplyViewContext ctx, SLE::const_ref accSle, XRPAmount accBalance, SLE::const_ref sponsorSle, Adjustment adj, beast::Journal j, TER insufReserveCode=tecINSUFFICIENT_RESERVE)
Check if an account has sufficient reserve.
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
@ tecNO_LINE_INSUF_RESERVE
STAmount divideRound(STAmount const &amount, Rate const &rate, bool roundUp)
Bundles the mutable ledger view and the transaction being applied.
A pair of SHAMap key and LedgerEntryType.
Represents a transfer rate.