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/protocol/AccountID.h>
10#include <xrpl/protocol/Concepts.h>
11#include <xrpl/protocol/Feature.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/Rate.h>
14#include <xrpl/protocol/SField.h>
15#include <xrpl/protocol/STAmount.h>
16#include <xrpl/protocol/STLedgerEntry.h>
17#include <xrpl/protocol/STTx.h>
18#include <xrpl/protocol/SeqProxy.h>
19#include <xrpl/protocol/TER.h>
20#include <xrpl/protocol/XRPAmount.h>
21#include <xrpl/tx/Transactor.h>
43 AccountID const account = (*escrow)[sfAccount];
44 STAmount const amount = (*escrow)[sfAmount];
49 [&]<
typename T>(T
const&) {
52 amount.
asset().value());
67 if (
ctx_.view().rules().enabled(featureTokenEscrow))
73 auto const now =
ctx_.view().header().parentCloseTime;
76 if (!(*escrow)[~sfCancelAfter])
80 if (!
after(now, (*escrow)[sfCancelAfter]))
83 AccountID const account = (*escrow)[sfAccount];
87 auto const page = (*escrow)[sfOwnerNode];
91 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from owner.";
98 if (
auto const optPage = (*escrow)[~sfDestinationNode]; optPage)
100 if (!
ctx_.view().dirRemove(
104 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from recipient.";
111 STAmount const amount = escrow->getFieldAmount(sfAmount);
117 bool const recycleReserve =
ctx_.view().rules().enabled(fixCleanup3_4_0);
121 ctx_.view(), sle, escrow.mutableRawSle(), reserveToSubtract,
ctx_.journal);
127 (*sle)[sfBalance] = (*sle)[sfBalance] + amount;
131 if (!
ctx_.view().rules().enabled(featureTokenEscrow))
135 bool const createAsset = account ==
accountID_;
137 [&]<
typename T>(T
const&) {
139 ctx_.getApplyViewContext(),
141 ctx_.view().rules().enabled(fixCleanup3_2_0) ? sle : escrow.mutableRawSle(),
150 amount.
asset().value());
155 if (
auto const optPage = (*escrow)[~sfIssuerNode]; optPage)
160 JLOG(
j_.fatal()) <<
"Unable to delete Escrow from recipient.";
170 ctx_.view(), sle, escrow.mutableRawSle(), reserveToSubtract,
ctx_.journal);
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.
virtual Rules const & rules() const =0
Returns the tx processing rules.
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool isXRP(AccountID const &c)
int32_t calculateAdditionalReserve(T const &finishFunction)
Owner count an escrow costs.
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)
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.
TER escrowUnlockPreclaimHelper(ReadView const &view, AccountID const &account, STAmount const &amount, bool checkFreeze=true)
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.
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.