1#include <xrpl/tx/apply.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/core/HashRouter.h>
8#include <xrpl/core/ServiceRegistry.h>
9#include <xrpl/ledger/ApplyView.h>
10#include <xrpl/ledger/OpenView.h>
11#include <xrpl/protocol/Rules.h>
12#include <xrpl/protocol/SField.h>
13#include <xrpl/protocol/STObject.h>
14#include <xrpl/protocol/STTx.h>
15#include <xrpl/protocol/TER.h>
16#include <xrpl/protocol/TxFlags.h>
17#include <xrpl/protocol/TxFormats.h>
18#include <xrpl/tx/applySteps.h>
39 auto const flags = router.
getFlags(
id);
48 return {
Validity::SigBad,
"Batch inner transactions are never considered validly signed."};
59 auto const sigVerify = tx.
checkSign(rules);
114template <
typename PreflightChecks>
118 return doApply(
preclaim(preflightChecks(), registry, view), registry, view);
125 registry, view, [&]()
mutable {
return preflight(registry, view.
rules(), tx, flags, j); });
137 return apply(registry, view, [&]()
mutable {
138 return preflight(registry, view.
rules(), parentBatchId, tx, flags, j);
146 STTx const& batchTxn,
151 "Batch transaction missing sfRawTransactions");
154 auto const mode = batchTxn.
getFlags();
156 auto applyOneTransaction = [®istry, &j, &parentBatchId, &batchView](
STTx const& tx) {
159 auto const ret =
apply(registry, perTxBatchView, parentBatchId, tx,
TapBatch, j);
162 "Inner transaction should not be applied");
164 JLOG(j.
debug()) <<
"BatchTrace[" << parentBatchId <<
"]: " << tx.getTransactionID() <<
" "
165 << (ret.applied ?
"applied" :
"failure") <<
": " <<
transToken(ret.ter);
173 perTxBatchView.
apply(batchView);
182 auto const result = applyOneTransaction(*stx);
185 "Outer Batch failure, inner transaction should not be applied");
192 if ((mode & tfAllOrNothing) != 0u)
195 if ((mode & tfUntilFailure) != 0u)
198 else if ((mode & tfOnlyOne) != 0u)
224 auto const result =
apply(registry, view, txn, flags, j);
237 wholeBatchView.
apply(view);
255 JLOG(j.
warn()) <<
"Throws: " << ex.
what();
A generic endpoint for log messages.
Routing table for objects identified by hash.
HashRouterFlags getFlags(uint256 const &key)
bool setFlags(uint256 const &key, HashRouterFlags flags)
Set the flags on a hash.
Writable ledger view that accumulates state and tx changes.
void apply(TxsRawView &to) const
Apply changes.
Rules const & rules() const override
Returns the tx processing rules.
Rules controlling protocol behavior.
STArray const & getFieldArray(SField const &field) const
bool isFlag(std::uint32_t) const
std::uint32_t getFlags() const
std::expected< void, std::string > checkSign(Rules const &rules) const
Check the signature.
TxType getTxnType() const
uint256 getTransactionID() const
std::vector< std::shared_ptr< STTx const > > const & getBatchTransactions() const
The inner transactions of a Batch, built and validated at construction.
Service registry for dependency injection.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr HashRouterFlags kSfSigbad
constexpr FlagValue tfInnerBatchTxn
PreflightResult preflight(ServiceRegistry ®istry, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
PreclaimResult preclaim(PreflightResult const &preflightResult, ServiceRegistry ®istry, OpenView const &view)
Gate a transaction based on static ledger information.
Validity
Describes the pre-processing validity of a transaction.
@ SigBad
Signature is bad.
@ Valid
Signature and local checks are good / passed.
@ SigGoodOnly
Signature is good, but local checks fail.
ApplyResult apply(ServiceRegistry ®istry, OpenView &view, STTx const &tx, ApplyFlags flags, beast::Journal journal)
Apply a transaction to an OpenView.
constexpr struct xrpl::BatchViewT kBatchView
ApplyTransactionResult applyTransaction(ServiceRegistry ®istry, OpenView &view, STTx const &tx, bool retryAssured, ApplyFlags flags, beast::Journal journal)
Transaction application helper.
std::pair< Validity, std::string > checkValidity(HashRouter &router, STTx const &tx, Rules const &rules)
Checks transaction signature and local checks.
constexpr HashRouterFlags kSfSiggood
ApplyTransactionResult
Enum class for return value from applyTransaction.
@ Success
Applied to this ledger.
@ Retry
Should be retried in this ledger.
@ Fail
Should not be retried in this ledger.
std::string transHuman(TER code)
std::string transToken(TER code)
bool passesLocalChecks(STTx const &tx, std::string &)
bool isTefFailure(TER x) noexcept
static bool applyBatchTransactions(ServiceRegistry ®istry, OpenView &batchView, STTx const &batchTxn, beast::Journal j)
bool isTelLocal(TER x) noexcept
bool isTesSuccess(TER x) noexcept
bool isTecClaim(TER x) noexcept
void forceValidity(HashRouter &router, uint256 const &txid, Validity validity)
Sets the validity of a given transaction in the cache.
ApplyResult doApply(PreclaimResult const &preclaimResult, ServiceRegistry ®istry, OpenView &view)
Apply a prechecked transaction to an OpenView.
constexpr HashRouterFlags kSfLocalgood
bool isTemMalformed(TER x) noexcept
constexpr bool any(HashRouterFlags flags)
constexpr HashRouterFlags kSfLocalbad