1#include <xrpl/tx/applySteps.h>
2#pragma push_macro("TRANSACTION")
6#define TRANSACTION(...)
7#define TRANSACTION_INCLUDE 1
9#include <xrpl/protocol/detail/transactions.macro>
12#pragma pop_macro("TRANSACTION")
17#include <xrpl/core/ServiceRegistry.h>
18#include <xrpl/protocol/TxFormats.h>
29 UnknownTxnType(
TxType t) : txnType{t}
38with_txn_type(Rules
const& rules,
TxType txnType, F&& f)
56 if (rules.enabled(featureSingleAssetVault) || rules.enabled(featureLendingProtocol))
60 stNumberSO.
emplace(rules.enabled(fixUniversalNumber));
71#pragma push_macro("TRANSACTION")
74#define TRANSACTION(tag, value, name, ...) \
76 return f.template operator()<name>();
78#include <xrpl/protocol/detail/transactions.macro>
81#pragma pop_macro("TRANSACTION")
83 throw UnknownTxnType(txnType);
122 return T::makeTxConsequences(ctx);
131 auto const tec = Transactor::invokePreflight<T>(ctx);
132 return std::make_pair(
133 tec, isTesSuccess(tec) ? consequences_helper<T>(ctx) : TxConsequences{tec});
136 catch (UnknownTxnType
const& e)
140 JLOG(ctx.
j.
fatal()) <<
"Unknown transaction type in preflight: " << e.txnType;
141 UNREACHABLE(
"xrpl::invoke_preflight : unknown transaction type");
167 auto const id = ctx.tx.getAccountID(sfAccount);
169 if (id != beast::zero)
171 if (NotTEC const preSigResult = [&]() -> NotTEC {
172 if (NotTEC const result = T::checkSeqProxy(ctx.view, ctx.tx, ctx.j))
175 if (NotTEC const result = T::checkPriorTxAndLastLedger(ctx))
178 if (NotTEC const result = T::checkPermission(ctx.view, ctx.tx))
181 if (NotTEC const result = T::checkSign(ctx))
188 if (TER const result = T::checkFee(ctx, calculateBaseFee(ctx.view, ctx.tx)))
192 return T::preclaim(ctx);
195 catch (UnknownTxnType
const& e)
199 JLOG(ctx.
j.
fatal()) <<
"Unknown transaction type in preclaim: " << e.txnType;
200 UNREACHABLE(
"xrpl::invoke_preclaim : unknown transaction type");
227 return with_txn_type(view.
rules(), tx.
getTxnType(), [&]<
typename T>() {
228 return T::calculateBaseFee(view, tx);
231 catch (UnknownTxnType
const& e)
234 UNREACHABLE(
"xrpl::invoke_calculateBaseFee : unknown transaction type");
240TxConsequences::TxConsequences(
NotTEC pfResult)
243 , potentialSpend_(
beast::zero)
245 , sequencesConsumed_(0)
248 !
isTesSuccess(pfResult),
"xrpl::TxConsequences::TxConsequences : is not tesSUCCESS");
253 , fee_(tx[sfFee].native() && !tx[sfFee].negative() ? tx[sfFee].xrp() :
beast::zero)
254 , potentialSpend_(
beast::zero)
255 , seqProx_(tx.getSeqProxy())
256 , sequencesConsumed_(tx.getSeqProxy().isSeq() ? 1 : 0)
285 catch (UnknownTxnType
const& e)
289 JLOG(ctx.
journal.
fatal()) <<
"Unknown transaction type in apply: " << e.txnType;
290 UNREACHABLE(
"xrpl::invoke_apply : unknown transaction type");
311 JLOG(j.
fatal()) <<
"apply (preflight): " << e.
what();
332 JLOG(j.
fatal()) <<
"apply (preflight): " << e.
what();
343 auto secondFlight = [&]() {
351 preflightResult.
flags,
359 preflightResult.
flags,
369 secondFlight.parentBatchId,
379 preflightResult.
flags,
387 return {*ctx, ctx->preflightResult};
392 JLOG(ctx->j.fatal()) <<
"apply (preclaim): " << e.
what();
421 return {preclaimResult.
ter,
false};
429 preclaimResult.
flags,
435 JLOG(preclaimResult.
j.
fatal()) <<
"apply: " << e.
what();
A generic endpoint for log messages.
State information when applying a tx.
beast::Journal const journal
Writable ledger view that accumulates state and tx changes.
Rules const & rules() const override
Returns the tx processing rules.
virtual Rules const & rules() const =0
Returns the tx processing rules.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Rules controlling protocol behavior.
TxType getTxnType() const
A type that represents either a sequence value or a ticket value.
Service registry for dependency injection.
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Class describing the consequences to the account of applying a transaction if the transaction consume...
TxConsequences(NotTEC pfResult)
std::uint32_t sequencesConsumed_
Number of sequences consumed.
Category
Describes how the transaction affects subsequent transactions.
@ blocker
Affects the ability of subsequent transactions to claim a fee.
XRPAmount potentialSpend_
Does NOT include the fee.
bool isBlocker_
Describes how the transaction affects subsequent transactions.
std::uint32_t sequencesConsumed() const
Sequences consumed.
XRPAmount const & potentialSpend() const
Potential Spend.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static XRPAmount invoke_calculateBaseFee(ReadView const &view, STTx const &tx)
Calculates the base fee for a given transaction.
PreflightResult preflight(ServiceRegistry ®istry, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
TxType
Transaction type identifiers.
static ApplyResult invoke_apply(ApplyContext &ctx)
PreclaimResult preclaim(PreflightResult const &preflightResult, ServiceRegistry ®istry, OpenView const &view)
Gate a transaction based on static ledger information.
static std::pair< NotTEC, TxConsequences > invoke_preflight(PreflightContext const &ctx)
static TER invoke_preclaim(PreclaimContext const &ctx)
TERSubset< CanCvtToTER > TER
TxConsequences consequences_helper(PreflightContext const &ctx)
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
bool isTesSuccess(TER x) noexcept
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
ApplyResult doApply(PreclaimResult const &preclaimResult, ServiceRegistry ®istry, OpenView &view)
Apply a prechecked transaction to an OpenView.
State information when determining if a tx is likely to claim a fee.
Describes the results of the preclaim check.
ReadView const & view
From the input - the ledger view.
std::optional< uint256 const > const parentBatchId
From the input - the batch identifier, if part of a batch.
TER const ter
Intermediate transaction result.
ApplyFlags const flags
From the input - the flags.
STTx const & tx
From the input - the transaction.
beast::Journal const j
From the input - the journal.
bool const likelyToClaimFee
Success flag - whether the transaction is likely to claim a fee.
State information when preflighting a tx.
Describes the results of the preflight check.
beast::Journal const j
From the input - the journal.
ApplyFlags const flags
From the input - the flags.
Rules const rules
From the input - the rules.
NotTEC const ter
Intermediate transaction result.
std::optional< uint256 const > const parentBatchId
From the input - the batch identifier, if part of a batch.
STTx const & tx
From the input - the transaction.