1#include <xrpl/tx/applySteps.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Number.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/utility/Zero.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/ledger/ApplyView.h>
9#include <xrpl/ledger/OpenView.h>
10#include <xrpl/protocol/Rules.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/SeqProxy.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/XRPAmount.h>
15#include <xrpl/tx/ApplyContext.h>
16#include <xrpl/tx/Transactor.h>
23#pragma push_macro("TRANSACTION")
27#define TRANSACTION(...)
28#define TRANSACTION_INCLUDE 1
30#include <xrpl/protocol/detail/transactions.macro>
33#pragma pop_macro("TRANSACTION")
38#include <xrpl/core/ServiceRegistry.h>
39#include <xrpl/protocol/TxFormats.h>
45struct UnknownTxnType : std::exception
48 UnknownTxnType(
TxType t) : txnType{t}
57withTxnType(
Rules const& rules,
TxType txnType, F&& f)
72 std::optional<CurrentTransactionRulesGuard> rulesGuard;
73 std::optional<NumberMantissaScaleGuard> mantissaScaleGuard;
78#pragma push_macro("TRANSACTION")
81#define TRANSACTION(tag, value, name, ...) \
83 return f.template operator()<name>();
85#include <xrpl/protocol/detail/transactions.macro>
88#pragma pop_macro("TRANSACTION")
90 throw UnknownTxnType(txnType);
128 return T::makeTxConsequences(ctx);
131static std::pair<NotTEC, TxConsequences>
137 auto const tec = Transactor::invokePreflight<T>(ctx);
138 return std::make_pair(
139 tec, isTesSuccess(tec) ? consequencesHelper<T>(ctx) : TxConsequences{tec});
142 catch (UnknownTxnType
const& e)
146 JLOG(ctx.j.fatal()) <<
"Unknown transaction type in preflight: " << e.txnType;
147 UNREACHABLE(
"xrpl::invokePreflight : unknown transaction type");
173 auto const id = ctx.tx.getAccountID(sfAccount);
175 if (id != beast::kZero)
177 if (NotTEC const preSigResult = [&]() -> NotTEC {
178 if (NotTEC const result = T::checkSeqProxy(ctx.view, ctx.tx, ctx.j))
181 if (NotTEC const result = T::checkPriorTxAndLastLedger(ctx))
184 if (NotTEC const result =
185 Transactor::invokeCheckPermission<T>(ctx.view, ctx.tx))
188 if (NotTEC const result = T::checkSign(ctx))
195 if (TER const result = T::checkFee(ctx, calculateBaseFee(ctx.view, ctx.tx)))
199 return T::preclaim(ctx);
202 catch (UnknownTxnType
const& e)
206 JLOG(ctx.j.fatal()) <<
"Unknown transaction type in preclaim: " << e.txnType;
207 UNREACHABLE(
"xrpl::invokePreclaim : unknown transaction type");
235 return T::calculateBaseFee(view, tx);
238 catch (UnknownTxnType
const& e)
241 UNREACHABLE(
"xrpl::invoke_calculateBaseFee : unknown transaction type");
255 !
isTesSuccess(pfResult),
"xrpl::TxConsequences::TxConsequences : is not tesSUCCESS");
260 ,
fee_(tx[sfFee].native() && !tx[sfFee].negative() ? tx[sfFee].xrp() :
beast::kZero)
292 catch (UnknownTxnType
const& e)
296 JLOG(ctx.
journal.
fatal()) <<
"Unknown transaction type in apply: " << e.txnType;
297 UNREACHABLE(
"xrpl::invokeApply : unknown transaction type");
311 return std::make_unique<T>(ctx);
330 JLOG(j.
fatal()) <<
"apply (preflight): " << e.
what();
351 JLOG(j.
fatal()) <<
"apply (preflight): " << e.
what();
362 auto secondFlight = [&]() {
370 preflightResult.
flags,
378 preflightResult.
flags,
388 secondFlight.parentBatchId,
398 preflightResult.
flags,
406 return {*ctx, ctx->preflightResult};
411 JLOG(ctx->j.fatal()) <<
"apply (preclaim): " << e.
what();
440 return {preclaimResult.
ter,
false};
448 preclaimResult.
flags,
454 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.
SeqProxy seqProx_
SeqProxy of transaction.
XRPAmount fee_
Transaction fee.
constexpr XRPAmount
Convert XRP to drops (integral types).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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.
PreclaimResult preclaim(PreflightResult const &preflightResult, ServiceRegistry ®istry, OpenView const &view)
Gate a transaction based on static ledger information.
static TER invokePreclaim(PreclaimContext const &ctx)
void createGuards(Rules const &rules, std::optional< CurrentTransactionRulesGuard > &rulesGuard, std::optional< NumberMantissaScaleGuard > &mantissaScaleGuard)
static std::pair< NotTEC, TxConsequences > invokePreflight(PreflightContext const &ctx)
static XRPAmount invokeCalculateBaseFee(ReadView const &view, STTx const &tx)
Calculates the base fee for a given transaction.
TERSubset< CanCvtToNotTEC > NotTEC
std::unique_ptr< Transactor > makeTransactor(ApplyContext &ctx)
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
TxConsequences consequencesHelper(PreflightContext const &ctx)
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
static ApplyResult invokeApply(ApplyContext &ctx)
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.