rippled
Loading...
Searching...
No Matches
applySteps.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_TX_APPLYSTEPS_H_INCLUDED
21#define RIPPLE_TX_APPLYSTEPS_H_INCLUDED
22
23#include <xrpld/ledger/ApplyViewImpl.h>
24
25#include <xrpl/beast/utility/Journal.h>
26
27namespace ripple {
28
29class Application;
30class STTx;
31class TxQ;
32
34{
36 bool applied;
38
39 ApplyResult(TER t, bool a, std::optional<TxMeta> m = std::nullopt)
40 : ter(t), applied(a), metadata(std::move(m))
41 {
42 }
43};
44
48inline bool
50{
51 return isTecClaim(ter) && !(flags & tapRETRY);
52}
53
59{
60public:
63 enum Category {
65 normal = 0,
69 };
70
71private:
83
84public:
85 // Constructor if preflight returns a value other than tesSUCCESS.
86 // Asserts if tesSUCCESS is passed.
87 explicit TxConsequences(NotTEC pfresult);
88
90 explicit TxConsequences(STTx const& tx);
91
93 TxConsequences(STTx const& tx, Category category);
94
97
100
105 operator=(TxConsequences const&) = default;
111
114 fee() const
115 {
116 return fee_;
117 }
118
120 XRPAmount const&
122 {
123 return potentialSpend_;
124 }
125
128 seqProxy() const
129 {
130 return seqProx_;
131 }
132
136 {
137 return sequencesConsumed_;
138 }
139
141 bool
142 isBlocker() const
143 {
144 return isBlocker_;
145 }
146
147 // Return the SeqProxy that would follow this.
150 {
151 SeqProxy following = seqProx_;
152 following.advanceBy(sequencesConsumed());
153 return following;
154 }
155};
156
164{
165public:
167 STTx const& tx;
178
180 NotTEC const ter;
181
183 template <class Context>
185 Context const& ctx_,
187 : tx(ctx_.tx)
189 , rules(ctx_.rules)
190 , consequences(result.second)
191 , flags(ctx_.flags)
192 , j(ctx_.j)
193 , ter(result.first)
194 {
195 }
196
200 operator=(PreflightResult const&) = delete;
201};
202
210{
211public:
215 STTx const& tx;
222
224 TER const ter;
225
229
231 template <class Context>
232 PreclaimResult(Context const& ctx_, TER ter_)
233 : view(ctx_.view)
234 , tx(ctx_.tx)
236 , flags(ctx_.flags)
237 , j(ctx_.j)
238 , ter(ter_)
240 {
241 }
242
246 operator=(PreclaimResult const&) = delete;
247};
248
268 Application& app,
269 Rules const& rules,
270 STTx const& tx,
271 ApplyFlags flags,
273
276 Application& app,
277 Rules const& rules,
278 uint256 const& parentBatchId,
279 STTx const& tx,
280 ApplyFlags flags,
314 PreflightResult const& preflightResult,
315 Application& app,
316 OpenView const& view);
317
335calculateBaseFee(ReadView const& view, STTx const& tx);
336
349calculateDefaultBaseFee(ReadView const& view, STTx const& tx);
350
368doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view);
369
370} // namespace ripple
371
372#endif
A generic endpoint for log messages.
Definition: Journal.h:60
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:66
A view into a ledger.
Definition: ReadView.h:52
Rules controlling protocol behavior.
Definition: Rules.h:38
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:56
SeqProxy & advanceBy(std::uint32_t amount)
Definition: SeqProxy.h:104
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition: applySteps.h:59
XRPAmount fee_
Transaction fee.
Definition: applySteps.h:76
std::uint32_t sequencesConsumed() const
Sequences consumed.
Definition: applySteps.h:135
TxConsequences(TxConsequences &&)=default
Move constructor.
TxConsequences & operator=(TxConsequences &&)=default
Move assignment operator.
TxConsequences(TxConsequences const &)=default
Copy constructor.
SeqProxy followingSeq() const
Definition: applySteps.h:149
std::uint32_t sequencesConsumed_
Number of sequences consumed.
Definition: applySteps.h:82
XRPAmount const & potentialSpend() const
Potential Spend.
Definition: applySteps.h:121
SeqProxy seqProxy() const
SeqProxy.
Definition: applySteps.h:128
XRPAmount fee() const
Fee.
Definition: applySteps.h:114
bool isBlocker_
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:74
TxConsequences & operator=(TxConsequences const &)=default
Copy assignment operator.
bool isBlocker() const
Returns true if the transaction is a blocker.
Definition: applySteps.h:142
Category
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:63
@ normal
Moves currency around, creates offers, etc.
Definition: applySteps.h:65
@ blocker
Affects the ability of subsequent transactions to claim a fee.
Definition: applySteps.h:68
XRPAmount potentialSpend_
Does NOT include the fee.
Definition: applySteps.h:78
SeqProxy seqProx_
SeqProxy of transaction.
Definition: applySteps.h:80
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
PreflightResult preflight(Application &app, Rules const &rules, STTx const &tx, ApplyFlags flags, beast::Journal j)
Gate a transaction based on static information.
Definition: applySteps.cpp:325
ApplyResult doApply(PreclaimResult const &preclaimResult, Application &app, OpenView &view)
Apply a prechecked transaction to an OpenView.
Definition: applySteps.cpp:439
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
Definition: applySteps.cpp:427
PreclaimResult preclaim(PreflightResult const &preflightResult, Application &app, OpenView const &view)
Gate a transaction based on static ledger information.
Definition: applySteps.cpp:366
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:49
@ tesSUCCESS
Definition: TER.h:244
ApplyFlags
Definition: ApplyView.h:31
@ tapRETRY
Definition: ApplyView.h:40
bool isTecClaim(TER x) noexcept
Definition: TER.h:678
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
Definition: applySteps.cpp:433
STL namespace.
ApplyResult(TER t, bool a, std::optional< TxMeta > m=std::nullopt)
Definition: applySteps.h:39
std::optional< TxMeta > metadata
Definition: applySteps.h:37
Describes the results of the preclaim check.
Definition: applySteps.h:210
ApplyFlags const flags
From the input - the flags.
Definition: applySteps.h:219
TER const ter
Intermediate transaction result.
Definition: applySteps.h:224
PreclaimResult & operator=(PreclaimResult const &)=delete
Deleted copy assignment operator.
bool const likelyToClaimFee
Success flag - whether the transaction is likely to claim a fee.
Definition: applySteps.h:228
ReadView const & view
From the input - the ledger view.
Definition: applySteps.h:213
PreclaimResult(Context const &ctx_, TER ter_)
Constructor.
Definition: applySteps.h:232
beast::Journal const j
From the input - the journal.
Definition: applySteps.h:221
PreclaimResult(PreclaimResult const &)=default
std::optional< uint256 const > const parentBatchId
From the input - the batch identifier, if part of a batch.
Definition: applySteps.h:217
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:215
Describes the results of the preflight check.
Definition: applySteps.h:164
Rules const rules
From the input - the rules.
Definition: applySteps.h:171
PreflightResult & operator=(PreflightResult const &)=delete
Deleted copy assignment operator.
ApplyFlags const flags
From the input - the flags.
Definition: applySteps.h:175
PreflightResult(PreflightResult const &)=default
beast::Journal const j
From the input - the journal.
Definition: applySteps.h:177
NotTEC const ter
Intermediate transaction result.
Definition: applySteps.h:180
PreflightResult(Context const &ctx_, std::pair< NotTEC, TxConsequences > const &result)
Constructor.
Definition: applySteps.h:184
std::optional< uint256 const > const parentBatchId
From the input - the batch identifier, if part of a batch.
Definition: applySteps.h:169
TxConsequences const consequences
Consequences of the transaction.
Definition: applySteps.h:173
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:167