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);
123 return T::makeTxConsequences(ctx);
133 auto const tec = Transactor::invokePreflight<T>(ctx);
134 return std::make_pair(
135 tec, isTesSuccess(tec) ? consequences_helper<T>(ctx) : TxConsequences{tec});
138 catch (UnknownTxnType
const& e)
142 JLOG(ctx.
j.
fatal()) <<
"Unknown transaction type in preflight: " << e.txnType;
143 UNREACHABLE(
"xrpl::invoke_preflight : unknown transaction type");
169 auto const id = ctx.tx.getAccountID(sfAccount);
171 if (id != beast::zero)
173 if (NotTEC const preSigResult = [&]() -> NotTEC {
174 if (NotTEC const result = T::checkSeqProxy(ctx.view, ctx.tx, ctx.j))
177 if (NotTEC const result = T::checkPriorTxAndLastLedger(ctx))
180 if (NotTEC const result = T::checkPermission(ctx.view, ctx.tx))
183 if (NotTEC const result = T::checkSign(ctx))
190 if (TER const result = T::checkFee(ctx, calculateBaseFee(ctx.view, ctx.tx)))
194 return T::preclaim(ctx);
197 catch (UnknownTxnType
const& e)
201 JLOG(ctx.
j.
fatal()) <<
"Unknown transaction type in preclaim: " << e.txnType;
202 UNREACHABLE(
"xrpl::invoke_preclaim : unknown transaction type");
229 return with_txn_type(view.
rules(), tx.
getTxnType(), [&]<
typename T>() {
230 return T::calculateBaseFee(view, tx);
233 catch (UnknownTxnType
const& e)
236 UNREACHABLE(
"xrpl::invoke_calculateBaseFee : unknown transaction type");
242TxConsequences::TxConsequences(
NotTEC pfResult)
245 , potentialSpend_(
beast::zero)
247 , sequencesConsumed_(0)
250 !
isTesSuccess(pfResult),
"xrpl::TxConsequences::TxConsequences : is not tesSUCCESS");
255 , fee_(tx[sfFee].native() && !tx[sfFee].negative() ? tx[sfFee].xrp() :
beast::zero)
256 , potentialSpend_(
beast::zero)
257 , seqProx_(tx.getSeqProxy())
258 , sequencesConsumed_(tx.getSeqProxy().isSeq() ? 1 : 0)
287 catch (UnknownTxnType
const& e)
291 JLOG(ctx.
journal.
fatal()) <<
"Unknown transaction type in apply: " << e.txnType;
292 UNREACHABLE(
"xrpl::invoke_apply : unknown transaction type");
313 JLOG(j.
fatal()) <<
"apply (preflight): " << e.
what();
334 JLOG(j.
fatal()) <<
"apply (preflight): " << e.
what();
345 auto secondFlight = [&]() {
352 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.