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/entries/EscrowEntry.h>
7#include <xrpl/ledger/helpers/AccountRootHelpers.h>
8#include <xrpl/ledger/helpers/EscrowHelpers.h>
9#include <xrpl/ledger/helpers/MPTokenHelpers.h>
10#include <xrpl/ledger/helpers/RippleStateHelpers.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/MPTIssue.h>
18#include <xrpl/protocol/Rate.h>
19#include <xrpl/protocol/SField.h>
20#include <xrpl/protocol/STAmount.h>
21#include <xrpl/protocol/STLedgerEntry.h>
22#include <xrpl/protocol/STTx.h>
23#include <xrpl/protocol/SeqProxy.h>
24#include <xrpl/protocol/TER.h>
25#include <xrpl/protocol/XRPAmount.h>
26#include <xrpl/tx/Transactor.h>
38template <Val
idIssueType T>
54 if (issuer == account)
73 if (issuer == account)
78 auto const sleIssuance = ctx.
view.
read(issuanceKey);
102 AccountID const account = (*escrow)[sfAccount];
103 STAmount const amount = (*escrow)[sfAmount];
108 [&]<
typename T>(T
const&) {
111 amount.
asset().value());
126 if (
ctx_.view().rules().enabled(featureTokenEscrow))
132 auto const now =
ctx_.view().header().parentCloseTime;
135 if (!(*escrow)[~sfCancelAfter])
139 if (!
after(now, (*escrow)[sfCancelAfter]))
142 AccountID const account = (*escrow)[sfAccount];
146 auto const page = (*escrow)[sfOwnerNode];
150 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from owner.";
157 if (
auto const optPage = (*escrow)[~sfDestinationNode]; optPage)
159 if (!
ctx_.view().dirRemove(
163 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from recipient.";
170 STAmount const amount = escrow->getFieldAmount(sfAmount);
174 bool const recycleReserve =
ctx_.view().rules().enabled(fixCleanup3_4_0);
181 (*sle)[sfBalance] = (*sle)[sfBalance] + amount;
185 if (!
ctx_.view().rules().enabled(featureTokenEscrow))
189 bool const createAsset = account ==
accountID_;
191 [&]<
typename T>(T
const&) {
193 ctx_.getApplyViewContext(),
195 ctx_.view().rules().enabled(fixCleanup3_2_0) ? sle : escrow.mutableRawSle(),
204 amount.
asset().value());
209 if (
auto const optPage = (*escrow)[~sfIssuerNode]; optPage)
214 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from recipient.";
A generic endpoint for log messages.
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
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 & ConstRef
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
AccountID const accountID_
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isXRP(AccountID const &c)
TER escrowCancelPreclaimHelper< MPTIssue >(PreclaimContext const &ctx, AccountID const &account, STAmount const &amount)
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)
TER escrowCancelPreclaimHelper< Issue >(PreclaimContext const &ctx, AccountID const &account, STAmount const &amount)
EscrowEntry< ReadView > EscrowEntryR
TERSubset< CanCvtToNotTEC > NotTEC
void decreaseOwnerCountForObject(ApplyView &view, SLE::Ref accountSle, SLE::Ref objectSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields for an existing ledger object.
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.
EscrowEntry< ApplyView > EscrowEntryW
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.