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 <optional>
16#include <utility>
17
18namespace xrpl {
19
20class ServiceRegistry;
21class STTx;
22class TxQ;
23
25{
27 bool applied;
29
30 ApplyResult(TER t, bool a, std::optional<TxMeta> m = std::nullopt)
31 : ter(t), applied(a), metadata(std::move(m))
32 {
33 }
34};
35
40inline bool
42{
43 return isTecClaim(ter) && ((flags & TapRetry) == 0u);
44}
45
52{
53public:
58 enum class Category {
62 Normal = 0,
68 };
69
70private:
92
93public:
94 // Constructor if preflight returns a value other than tesSUCCESS.
95 // Asserts if tesSUCCESS is passed.
96 explicit TxConsequences(NotTEC pfResult);
97
101 explicit TxConsequences(STTx const& tx);
102
106 TxConsequences(STTx const& tx, Category category);
107
112
117
126 operator=(TxConsequences const&) = default;
136
140 [[nodiscard]] XRPAmount
141 fee() const
142 {
143 return fee_;
144 }
145
149 [[nodiscard]] XRPAmount const&
151 {
152 return potentialSpend_;
153 }
154
158 [[nodiscard]] SeqProxy
159 seqProxy() const
160 {
161 return seqProx_;
162 }
163
167 [[nodiscard]] std::uint32_t
169 {
170 return sequencesConsumed_;
171 }
172
176 [[nodiscard]] bool
177 isBlocker() const
178 {
179 return isBlocker_;
180 }
181
182 // Return the SeqProxy that would follow this.
183 [[nodiscard]] SeqProxy
185 {
186 SeqProxy following = seqProx_;
187 following.advanceBy(sequencesConsumed());
188 return following;
189 }
190};
191
200{
201public:
205 STTx const& tx;
226
230 NotTEC const ter;
231
235 template <class Context>
236 PreflightResult(Context const& ctx, std::pair<NotTEC, TxConsequences> const& result)
237 : tx(ctx.tx)
239 , rules(ctx.rules)
240 , consequences(result.second)
241 , flags(ctx.flags)
242 , j(ctx.j)
243 , ter(result.first)
244 {
245 }
246
252 operator=(PreflightResult const&) = delete;
253};
254
263{
264public:
272 STTx const& tx;
285
289 TER const ter;
290
295 bool const likelyToClaimFee{};
296
300 template <class Context>
301 PreclaimResult(Context const& ctx, TER ter)
302 : view(ctx.view)
303 , tx(ctx.tx)
305 , flags(ctx.flags)
306 , j(ctx.j)
307 , ter(ter)
309 {
310 }
311
317 operator=(PreclaimResult const&) = delete;
318};
319
340 ServiceRegistry& registry,
341 Rules const& rules,
342 STTx const& tx,
343 ApplyFlags flags,
345
348 ServiceRegistry& registry,
349 Rules const& rules,
350 uint256 const& parentBatchId,
351 STTx const& tx,
352 ApplyFlags flags,
355
386preclaim(PreflightResult const& preflightResult, ServiceRegistry& registry, OpenView const& view);
387
406calculateBaseFee(ReadView const& view, STTx const& tx);
407
421calculateDefaultBaseFee(ReadView const& view, STTx const& tx);
422
441doApply(PreclaimResult const& preclaimResult, ServiceRegistry& registry, OpenView& view);
442
443} // 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:52
TxConsequences(NotTEC pfResult)
std::uint32_t sequencesConsumed_
Number of sequences consumed.
Definition applySteps.h:91
Category
Describes how the transaction affects subsequent transactions.
Definition applySteps.h:58
@ Normal
Moves currency around, creates offers, etc.
Definition applySteps.h:62
@ Blocker
Affects the ability of subsequent transactions to claim a fee.
Definition applySteps.h:67
SeqProxy seqProxy() const
SeqProxy.
Definition applySteps.h:159
XRPAmount potentialSpend_
Does NOT include the fee.
Definition applySteps.h:83
bool isBlocker_
Describes how the transaction affects subsequent transactions.
Definition applySteps.h:75
bool isBlocker() const
Returns true if the transaction is a blocker.
Definition applySteps.h:177
std::uint32_t sequencesConsumed() const
Sequences consumed.
Definition applySteps.h:168
XRPAmount const & potentialSpend() const
Potential Spend.
Definition applySteps.h:150
TxConsequences & operator=(TxConsequences const &)=default
Copy assignment operator.
SeqProxy followingSeq() const
Definition applySteps.h:184
SeqProxy seqProx_
SeqProxy of transaction.
Definition applySteps.h:87
XRPAmount fee_
Transaction fee.
Definition applySteps.h:79
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:141
Transaction Queue.
Definition TxQ.h:58
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.
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:41
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:607
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
ApplyFlags
Definition ApplyView.h:27
@ TapRetry
Definition ApplyView.h:36
bool isTesSuccess(TER x) noexcept
Definition TER.h:676
TERSubset< CanCvtToTER > TER
Definition TER.h:647
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
bool isTecClaim(TER x) noexcept
Definition TER.h:683
ApplyResult doApply(PreclaimResult const &preclaimResult, ServiceRegistry &registry, OpenView &view)
Apply a prechecked transaction to an OpenView.
BaseUInt< 256 > uint256
Definition base_uint.h:580
std::optional< TxMeta > metadata
Definition applySteps.h:28
ApplyResult(TER t, bool a, std::optional< TxMeta > m=std::nullopt)
Definition applySteps.h:30
Describes the results of the preclaim check.
Definition applySteps.h:263
ReadView const & view
From the input - the ledger view.
Definition applySteps.h:268
std::optional< uint256 const > const parentBatchId
From the input - the batch identifier, if part of a batch.
Definition applySteps.h:276
PreclaimResult(Context const &ctx, TER ter)
Constructor.
Definition applySteps.h:301
TER const ter
Intermediate transaction result.
Definition applySteps.h:289
ApplyFlags const flags
From the input - the flags.
Definition applySteps.h:280
PreclaimResult(PreclaimResult const &)=default
STTx const & tx
From the input - the transaction.
Definition applySteps.h:272
PreclaimResult & operator=(PreclaimResult const &)=delete
Deleted copy assignment operator.
beast::Journal const j
From the input - the journal.
Definition applySteps.h:284
bool const likelyToClaimFee
Success flag - whether the transaction is likely to claim a fee.
Definition applySteps.h:295
Describes the results of the preflight check.
Definition applySteps.h:200
TxConsequences const consequences
Consequences of the transaction.
Definition applySteps.h:217
PreflightResult & operator=(PreflightResult const &)=delete
Deleted copy assignment operator.
beast::Journal const j
From the input - the journal.
Definition applySteps.h:225
ApplyFlags const flags
From the input - the flags.
Definition applySteps.h:221
Rules const rules
From the input - the rules.
Definition applySteps.h:213
PreflightResult(Context const &ctx, std::pair< NotTEC, TxConsequences > const &result)
Constructor.
Definition applySteps.h:236
NotTEC const ter
Intermediate transaction result.
Definition applySteps.h:230
PreflightResult(PreflightResult const &)=default
std::optional< uint256 const > const parentBatchId
From the input - the batch identifier, if part of a batch.
Definition applySteps.h:209
STTx const & tx
From the input - the transaction.
Definition applySteps.h:205