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#include <xrpl/beast/utility/Journal.h>
25
26namespace ripple {
27
28class Application;
29class STTx;
30class TxQ;
31
33{
35 bool applied;
37
38 ApplyResult(TER t, bool a, std::optional<TxMeta> m = std::nullopt)
39 : ter(t), applied(a), metadata(std::move(m))
40 {
41 }
42};
43
47inline bool
49{
50 return isTecClaim(ter) && !(flags & tapRETRY);
51}
52
58{
59public:
62 enum Category {
64 normal = 0,
68 };
69
70private:
82
83public:
84 // Constructor if preflight returns a value other than tesSUCCESS.
85 // Asserts if tesSUCCESS is passed.
86 explicit TxConsequences(NotTEC pfresult);
87
89 explicit TxConsequences(STTx const& tx);
90
92 TxConsequences(STTx const& tx, Category category);
93
96
99
104 operator=(TxConsequences const&) = default;
110
113 fee() const
114 {
115 return fee_;
116 }
117
119 XRPAmount const&
121 {
122 return potentialSpend_;
123 }
124
127 seqProxy() const
128 {
129 return seqProx_;
130 }
131
135 {
136 return sequencesConsumed_;
137 }
138
140 bool
141 isBlocker() const
142 {
143 return isBlocker_;
144 }
145
146 // Return the SeqProxy that would follow this.
149 {
150 SeqProxy following = seqProx_;
151 following.advanceBy(sequencesConsumed());
152 return following;
153 }
154};
155
163{
164public:
166 STTx const& tx;
175
177 NotTEC const ter;
178
180 template <class Context>
182 Context const& ctx_,
184 : tx(ctx_.tx)
185 , rules(ctx_.rules)
186 , consequences(result.second)
187 , flags(ctx_.flags)
188 , j(ctx_.j)
189 , ter(result.first)
190 {
191 }
192
196 operator=(PreflightResult const&) = delete;
197};
198
206{
207public:
211 STTx const& tx;
216
218 TER const ter;
222
224 template <class Context>
225 PreclaimResult(Context const& ctx_, TER ter_)
226 : view(ctx_.view)
227 , tx(ctx_.tx)
228 , flags(ctx_.flags)
229 , j(ctx_.j)
230 , ter(ter_)
232 {
233 }
234
238 operator=(PreclaimResult const&) = delete;
239};
240
259 Application& app,
260 Rules const& rules,
261 STTx const& tx,
262 ApplyFlags flags,
264
295 PreflightResult const& preflightResult,
296 Application& app,
297 OpenView const& view);
298
316calculateBaseFee(ReadView const& view, STTx const& tx);
317
330calculateDefaultBaseFee(ReadView const& view, STTx const& tx);
331
349doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view);
350
351} // namespace ripple
352
353#endif
A generic endpoint for log messages.
Definition: Journal.h:59
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:56
A view into a ledger.
Definition: ReadView.h:55
Rules controlling protocol behavior.
Definition: Rules.h:35
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:58
XRPAmount fee_
Transaction fee.
Definition: applySteps.h:75
std::uint32_t sequencesConsumed() const
Sequences consumed.
Definition: applySteps.h:134
TxConsequences(TxConsequences &&)=default
Move constructor.
TxConsequences & operator=(TxConsequences &&)=default
Move assignment operator.
TxConsequences(TxConsequences const &)=default
Copy constructor.
SeqProxy followingSeq() const
Definition: applySteps.h:148
std::uint32_t sequencesConsumed_
Number of sequences consumed.
Definition: applySteps.h:81
XRPAmount const & potentialSpend() const
Potential Spend.
Definition: applySteps.h:120
SeqProxy seqProxy() const
SeqProxy.
Definition: applySteps.h:127
XRPAmount fee() const
Fee.
Definition: applySteps.h:113
bool isBlocker_
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:73
TxConsequences & operator=(TxConsequences const &)=default
Copy assignment operator.
bool isBlocker() const
Returns true if the transaction is a blocker.
Definition: applySteps.h:141
Category
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:62
@ normal
Moves currency around, creates offers, etc.
Definition: applySteps.h:64
@ blocker
Affects the ability of subsequent transactions to claim a fee.
Definition: applySteps.h:67
XRPAmount potentialSpend_
Does NOT include the fee.
Definition: applySteps.h:77
SeqProxy seqProx_
SeqProxy of transaction.
Definition: applySteps.h:79
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool isTecClaim(TER x)
Definition: TER.h:662
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:296
ApplyResult doApply(PreclaimResult const &preclaimResult, Application &app, OpenView &view)
Apply a prechecked transaction to an OpenView.
Definition: applySteps.cpp:374
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
Definition: applySteps.cpp:362
PreclaimResult preclaim(PreflightResult const &preflightResult, Application &app, OpenView const &view)
Gate a transaction based on static ledger information.
Definition: applySteps.cpp:316
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:48
@ tesSUCCESS
Definition: TER.h:242
ApplyFlags
Definition: ApplyView.h:30
@ tapRETRY
Definition: ApplyView.h:39
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
Definition: applySteps.cpp:368
STL namespace.
ApplyResult(TER t, bool a, std::optional< TxMeta > m=std::nullopt)
Definition: applySteps.h:38
std::optional< TxMeta > metadata
Definition: applySteps.h:36
Describes the results of the preclaim check.
Definition: applySteps.h:206
ApplyFlags const flags
From the input - the flags.
Definition: applySteps.h:213
TER const ter
Intermediate transaction result.
Definition: applySteps.h:218
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:221
ReadView const & view
From the input - the ledger view.
Definition: applySteps.h:209
PreclaimResult(Context const &ctx_, TER ter_)
Constructor.
Definition: applySteps.h:225
beast::Journal const j
From the input - the journal.
Definition: applySteps.h:215
PreclaimResult(PreclaimResult const &)=default
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:211
Describes the results of the preflight check.
Definition: applySteps.h:163
Rules const rules
From the input - the rules.
Definition: applySteps.h:168
PreflightResult & operator=(PreflightResult const &)=delete
Deleted copy assignment operator.
ApplyFlags const flags
From the input - the flags.
Definition: applySteps.h:172
PreflightResult(PreflightResult const &)=default
beast::Journal const j
From the input - the journal.
Definition: applySteps.h:174
NotTEC const ter
Intermediate transaction result.
Definition: applySteps.h:177
PreflightResult(Context const &ctx_, std::pair< NotTEC, TxConsequences > const &result)
Constructor.
Definition: applySteps.h:181
TxConsequences const consequences
Consequences of the transaction.
Definition: applySteps.h:170
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:166