1#include <xrpl/tx/transactors/escrow/EscrowCancel.h>
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/EscrowHelpers.h>
8#include <xrpl/ledger/helpers/MPTokenHelpers.h>
9#include <xrpl/ledger/helpers/RippleStateHelpers.h>
10#include <xrpl/ledger/helpers/TokenHelpers.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/Concepts.h>
13#include <xrpl/protocol/Feature.h>
14#include <xrpl/protocol/Indexes.h>
15#include <xrpl/protocol/Issue.h>
16#include <xrpl/protocol/MPTIssue.h>
17#include <xrpl/protocol/Rate.h>
18#include <xrpl/protocol/SField.h>
19#include <xrpl/protocol/STAmount.h>
20#include <xrpl/protocol/STLedgerEntry.h>
21#include <xrpl/protocol/STTx.h>
22#include <xrpl/protocol/TER.h>
23#include <xrpl/protocol/XRPAmount.h>
24#include <xrpl/tx/Transactor.h>
36template <Val
idIssueType T>
52 if (issuer == account)
71 if (issuer == account)
76 auto const sleIssuance = ctx.
view.
read(issuanceKey);
100 AccountID const account = (*slep)[sfAccount];
101 STAmount const amount = (*slep)[sfAmount];
106 [&]<
typename T>(T
const&) {
109 amount.
asset().value());
121 auto const slep =
ctx_.view().peek(k);
124 if (
ctx_.view().rules().enabled(featureTokenEscrow))
130 auto const now =
ctx_.view().header().parentCloseTime;
133 if (!(*slep)[~sfCancelAfter])
137 if (!
after(now, (*slep)[sfCancelAfter]))
140 AccountID const account = (*slep)[sfAccount];
144 auto const page = (*slep)[sfOwnerNode];
148 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from owner.";
155 if (
auto const optPage = (*slep)[~sfDestinationNode]; optPage)
160 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from recipient.";
167 STAmount const amount = slep->getFieldAmount(sfAmount);
172 (*sle)[sfBalance] = (*sle)[sfBalance] + amount;
176 if (!
ctx_.view().rules().enabled(featureTokenEscrow))
180 bool const createAsset = account ==
accountID_;
182 [&]<
typename T>(T
const&) {
186 ctx_.view().rules().enabled(fixCleanup3_2_0) ? sle : slep,
195 amount.
asset().value());
200 if (
auto const optPage = (*slep)[~sfIssuerNode]; optPage)
205 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from recipient.";
213 ctx_.view().update(sle);
216 ctx_.view().erase(slep);
A generic endpoint for log messages.
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
A currency issued by an account.
constexpr MPTID const & getMptID() const
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual SLE::const_pointer 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
Asset const & asset() const
AccountID const & getIssuer() const
std::shared_ptr< STLedgerEntry const > const & const_ref
AccountID const accountID_
Keylet mptokenIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet escrow(AccountID const &src, std::uint32_t seq) noexcept
An escrow entry.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
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)
bool isXRP(AccountID const &c)
TER escrowCancelPreclaimHelper< MPTIssue >(PreclaimContext const &ctx, AccountID const &account, STAmount const &amount)
TER escrowCancelPreclaimHelper< Issue >(PreclaimContext const &ctx, AccountID const &account, STAmount const &amount)
TERSubset< CanCvtToNotTEC > NotTEC
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Rate const kParityRate
A transfer rate signifying a 1:1 exchange.
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
static TER escrowCancelPreclaimHelper(PreclaimContext const &ctx, AccountID const &account, STAmount const &amount)
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, std::uint8_t depth=0)
Check if the account lacks required authorization for MPT.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.