1#include <xrpl/basics/Log.h>
2#include <xrpl/basics/chrono.h>
3#include <xrpl/conditions/Condition.h>
4#include <xrpl/conditions/Fulfillment.h>
5#include <xrpl/core/HashRouter.h>
6#include <xrpl/ledger/ApplyView.h>
7#include <xrpl/ledger/View.h>
8#include <xrpl/ledger/helpers/CredentialHelpers.h>
9#include <xrpl/ledger/helpers/MPTokenHelpers.h>
10#include <xrpl/ledger/helpers/RippleStateHelpers.h>
11#include <xrpl/protocol/Feature.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/Rate.h>
14#include <xrpl/protocol/TxFlags.h>
15#include <xrpl/protocol/XRPAmount.h>
16#include <xrpl/tx/transactors/escrow/EscrowFinish.h>
18#include <libxrpl/tx/transactors/escrow/EscrowHelpers.h>
37 auto condition = Condition::deserialize(c, ec);
41 auto fulfillment = Fulfillment::deserialize(f, ec);
45 return validate(*fulfillment, *condition);
57 auto const cb = ctx.
tx[~sfCondition];
58 auto const fb = ctx.
tx[~sfFulfillment];
62 if (
static_cast<bool>(cb) !=
static_cast<bool>(fb))
71 auto const cb = ctx.
tx[~sfCondition];
72 auto const fb = ctx.
tx[~sfFulfillment];
76 auto& router = ctx.
registry.get().getHashRouter();
79 auto const flags = router.getFlags(
id);
108 if (
auto const fb = tx[~sfFulfillment])
110 extraFee +=
view.
fees().
base * (32 + (fb->size() / 16));
116template <Val
idIssueType T>
130 AccountID const issuer = amount.getIssuer();
153 AccountID const issuer = amount.getIssuer();
160 auto const sleIssuance = ctx.
view.
read(issuanceKey);
166 auto const& mptIssue = amount.get<
MPTIssue>();
195 AccountID const dest = (*slep)[sfDestination];
196 STAmount const amount = (*slep)[sfAmount];
201 [&]<
typename T>(T
const&) {
202 return escrowFinishPreclaimHelper<T>(ctx, dest, amount);
204 amount.asset().value());
230 if ((*slep)[~sfFinishAfter] && !
after(now, (*slep)[sfFinishAfter]))
234 if ((*slep)[~sfCancelAfter] &&
after(now, (*slep)[sfCancelAfter]))
240 auto flags =
ctx_.
registry.get().getHashRouter().getFlags(
id);
242 auto const cb =
ctx_.
tx[~sfCondition];
250 auto const fb =
ctx_.
tx[~sfFulfillment];
264 ctx_.
registry.get().getHashRouter().setFlags(
id, flags);
274 auto const cond = (*slep)[~sfCondition];
286 if (cond && (cond != cb))
291 AccountID const destID = (*slep)[sfDestination];
300 AccountID const account = (*slep)[sfAccount];
304 auto const page = (*slep)[sfOwnerNode];
308 JLOG(
j_.
fatal()) <<
"Unable to delete Escrow from owner.";
315 if (
auto const optPage = (*slep)[~sfDestinationNode])
320 JLOG(
j_.
fatal()) <<
"Unable to delete Escrow from recipient.";
326 STAmount const amount = slep->getFieldAmount(sfAmount);
330 (*sled)[sfBalance] = (*sled)[sfBalance] + amount;
337 Rate lockedRate = slep->isFieldPresent(sfTransferRate)
338 ?
xrpl::Rate(slep->getFieldU32(sfTransferRate))
340 auto const issuer = amount.getIssuer();
341 bool const createAsset = destID ==
account_;
343 [&]<
typename T>(T
const&) {
344 return escrowUnlockApplyHelper<T>(
356 amount.asset().value());
361 if (
auto const optPage = (*slep)[~sfIssuerNode]; optPage)
366 JLOG(
j_.
fatal()) <<
"Unable to delete Escrow from recipient.";
std::reference_wrapper< ServiceRegistry > registry
beast::Journal const journal
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
static bool checkExtraFeatures(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static NotTEC preflightSigValidated(PreflightContext const &ctx)
constexpr MPTID const & getMptID() const
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 LedgerHeader const & header() const =0
Returns information about the ledger.
virtual std::shared_ptr< SLE const > 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.
bool isFieldPresent(SField const &field) const
uint256 getTransactionID() const
An immutable linear range of bytes.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
NotTEC checkFields(STTx const &tx, beast::Journal j)
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
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 mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr HashRouterFlags SF_CF_VALID
bool isXRP(AccountID const &c)
static TER escrowFinishPreclaimHelper(PreclaimContext const &ctx, AccountID const &dest, STAmount const &amount)
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE const > const &sleDst, beast::Journal j)
bool isDeepFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
TER escrowFinishPreclaimHelper< Issue >(PreclaimContext const &ctx, AccountID const &dest, STAmount const &amount)
bool isFrozen(ReadView const &view, AccountID const &account, MPTIssue const &mptIssue, int depth=0)
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
TER escrowFinishPreclaimHelper< MPTIssue >(PreclaimContext const &ctx, AccountID const &dest, STAmount const &amount)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
static bool checkCondition(Slice f, Slice c)
bool isTesSuccess(TER x) noexcept
@ tecCRYPTOCONDITION_ERROR
constexpr HashRouterFlags SF_CF_INVALID
Rate const parityRate
A transfer rate signifying a 1:1 exchange.
TER requireAuth(ReadView const &view, MPTIssue const &mptIssue, AccountID const &account, AuthType authType=AuthType::Legacy, int depth=0)
Check if the account lacks required authorization for MPT.
XRPAmount base
Cost of a reference transaction in drops.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.
std::reference_wrapper< ServiceRegistry > registry
Represents a transfer rate.