xrpld
Loading...
Searching...
No Matches
applySteps.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/OpenView.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/protocol/Rules.h>
9#include <xrpl/protocol/SeqProxy.h>
10#include <xrpl/protocol/TER.h>
11#include <xrpl/protocol/TxMeta.h>
12#include <xrpl/protocol/XRPAmount.h>
13
14#include <cstdint>
15#include <expected>
16#include <optional>
17#include <utility>
18
19namespace xrpl {
20
21class ServiceRegistry;
22class STTx;
23class TxQ;
24
26{
28 bool applied;
30
31 ApplyResult(TER t, bool a, std::optional<TxMeta> m = std::nullopt)
32 : ter(t), applied(a), metadata(std::move(m))
33 {
34 }
35};
36
41inline bool
43{
44 return isTecClaim(ter) && ((flags & TapRetry) == 0u);
45}
46
53{
54public:
59 enum class Category {
63 Normal = 0,
69 };
70
71private:
93
94public:
95 // Constructor if preflight returns a value other than tesSUCCESS.
96 // Asserts if tesSUCCESS is passed.
97 explicit TxConsequences(NotTEC pfResult);
98
102 explicit TxConsequences(STTx const& tx);
103
107 TxConsequences(STTx const& tx, Category category);
108
113
118
127 operator=(TxConsequences const&) = default;
137
141 [[nodiscard]] XRPAmount
142 fee() const
143 {
144 return fee_;
145 }
146
150 [[nodiscard]] XRPAmount const&
152 {
153 return potentialSpend_;
154 }
155
159 [[nodiscard]] SeqProxy
160 seqProxy() const
161 {
162 return seqProx_;
163 }
164
168 [[nodiscard]] std::uint32_t
170 {
171 return sequencesConsumed_;
172 }
173
177 [[nodiscard]] bool
178 isBlocker() const
179 {
180 return isBlocker_;
181 }
182
183 // Return the SeqProxy that would follow this.
184 [[nodiscard]] SeqProxy
186 {
187 SeqProxy following = seqProx_;
188 following.advanceBy(sequencesConsumed());
189 return following;
190 }
191};
192
201{
202public:
206 STTx const& tx;
227
231 NotTEC const ter;
232
236 template <class Context>
237 PreflightResult(Context const& ctx, std::pair<NotTEC, TxConsequences> const& result)
238 : tx(ctx.tx)
240 , rules(ctx.rules)
241 , consequences(result.second)
242 , flags(ctx.flags)
243 , j(ctx.j)
244 , ter(result.first)
245 {
246 }
247
253 operator=(PreflightResult const&) = delete;
254};
255
264{
265public:
273 STTx const& tx;
286
290 TER const ter;
291
296 bool const likelyToClaimFee{};
297
301 template <class Context>
302 PreclaimResult(Context const& ctx, TER ter)
303 : view(ctx.view)
304 , tx(ctx.tx)
306 , flags(ctx.flags)
307 , j(ctx.j)
308 , ter(ter)
310 {
311 }
312
318 operator=(PreclaimResult const&) = delete;
319};
320
341 ServiceRegistry& registry,
342 Rules const& rules,
343 STTx const& tx,
344 ApplyFlags flags,
346
349 ServiceRegistry& registry,
350 Rules const& rules,
351 UInt256 const& parentBatchId,
352 STTx const& tx,
353 ApplyFlags flags,
356
387preclaim(PreflightResult const& preflightResult, ServiceRegistry& registry, OpenView const& view);
388
403NotTEC
404invokeCheckPermission(ReadView const& view, STTx const& tx);
405
428[[nodiscard]] std::expected<XRPAmount, TER>
429calculateBaseFee(ReadView const& view, STTx const& tx);
430
444calculateDefaultBaseFee(ReadView const& view, STTx const& tx);
445
464doApply(PreclaimResult const& preclaimResult, ServiceRegistry& registry, OpenView& view);
465
466} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:59
A view into a ledger.
Definition ReadView.h:41
Rules controlling protocol behavior.
Definition Rules.h:40
A type that represents either a sequence value or a ticket value.
Definition SeqProxy.h:37
SeqProxy & advanceBy(std::uint32_t amount)
Definition SeqProxy.h:102
Service registry for dependency injection.
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition applySteps.h:53
TxConsequences(NotTEC pfResult)
std::uint32_t sequencesConsumed_
Number of sequences consumed.
Definition applySteps.h:92
Category
Describes how the transaction affects subsequent transactions.
Definition applySteps.h:59
@ Normal
Moves currency around, creates offers, etc.
Definition applySteps.h:63
@ Blocker
Affects the ability of subsequent transactions to claim a fee.
Definition applySteps.h:68
SeqProxy seqProxy() const
SeqProxy.
Definition applySteps.h:160
XRPAmount potentialSpend_
Does NOT include the fee.
Definition applySteps.h:84
bool isBlocker_
Describes how the transaction affects subsequent transactions.
Definition applySteps.h:76
bool isBlocker() const
Returns true if the transaction is a blocker.
Definition applySteps.h:178
std::uint32_t sequencesConsumed() const
Sequences consumed.
Definition applySteps.h:169
XRPAmount const & potentialSpend() const
Potential Spend.
Definition applySteps.h:151
TxConsequences & operator=(TxConsequences const &)=default
Copy assignment operator.
SeqProxy followingSeq() const
Definition applySteps.h:185
SeqProxy seqProx_
SeqProxy of transaction.
Definition applySteps.h:88
XRPAmount fee_
Transaction fee.
Definition applySteps.h:80
TxConsequences & operator=(TxConsequences &&)=default
Move assignment operator.
TxConsequences(TxConsequences const &)=default
Copy constructor.
TxConsequences(TxConsequences &&)=default
Move constructor.
XRPAmount fee() const
Fee.
Definition applySteps.h:142
Transaction Queue.
Definition TxQ.h:59
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
PreflightResult preflight(ServiceRegistry &registry, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
PreclaimResult preclaim(PreflightResult const &preflightResult, ServiceRegistry &registry, OpenView const &view)
Gate a transaction based on static ledger information.
std::expected< XRPAmount, TER > calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
bool isTecClaimHardFail(TER ter, ApplyFlags flags)
Return true if the transaction can claim a fee (tec), and the ApplyFlags do not allow soft failures.
Definition applySteps.h:42
BaseUInt< 256 > UInt256
Definition base_uint.h:580
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:614
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
NotTEC invokeCheckPermission(ReadView const &view, STTx const &tx)
Type-erased overload of Transactor::invokeCheckPermission.
ApplyFlags
Definition ApplyView.h:27
@ TapRetry
Definition ApplyView.h:36
bool isTesSuccess(TER x) noexcept
Definition TER.h:683
TERSubset< CanCvtToTER > TER
Definition TER.h:654
bool isTecClaim(TER x) noexcept
Definition TER.h:690
ApplyResult doApply(PreclaimResult const &preclaimResult, ServiceRegistry &registry, OpenView &view)
Apply a prechecked transaction to an OpenView.
std::optional< TxMeta > metadata
Definition applySteps.h:29
ApplyResult(TER t, bool a, std::optional< TxMeta > m=std::nullopt)
Definition applySteps.h:31
Describes the results of the preclaim check.
Definition applySteps.h:264
ReadView const & view
From the input - the ledger view.
Definition applySteps.h:269
PreclaimResult(Context const &ctx, TER ter)
Constructor.
Definition applySteps.h:302
TER const ter
Intermediate transaction result.
Definition applySteps.h:290
ApplyFlags const flags
From the input - the flags.
Definition applySteps.h:281
PreclaimResult(PreclaimResult const &)=default
STTx const & tx
From the input - the transaction.
Definition applySteps.h:273
std::optional< UInt256 const > const parentBatchId
From the input - the batch identifier, if part of a batch.
Definition applySteps.h:277
PreclaimResult & operator=(PreclaimResult const &)=delete
Deleted copy assignment operator.
beast::Journal const j
From the input - the journal.
Definition applySteps.h:285
bool const likelyToClaimFee
Success flag - whether the transaction is likely to claim a fee.
Definition applySteps.h:296
Describes the results of the preflight check.
Definition applySteps.h:201
TxConsequences const consequences
Consequences of the transaction.
Definition applySteps.h:218
PreflightResult & operator=(PreflightResult const &)=delete
Deleted copy assignment operator.
beast::Journal const j
From the input - the journal.
Definition applySteps.h:226
ApplyFlags const flags
From the input - the flags.
Definition applySteps.h:222
Rules const rules
From the input - the rules.
Definition applySteps.h:214
PreflightResult(Context const &ctx, std::pair< NotTEC, TxConsequences > const &result)
Constructor.
Definition applySteps.h:237
NotTEC const ter
Intermediate transaction result.
Definition applySteps.h:231
PreflightResult(PreflightResult const &)=default
STTx const & tx
From the input - the transaction.
Definition applySteps.h:206
std::optional< UInt256 const > const parentBatchId
From the input - the batch identifier, if part of a batch.
Definition applySteps.h:210