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;
176
178 NotTEC const ter;
179
181 template <class Context>
183 Context const& ctx_,
185 : tx(ctx_.tx)
186 , rules(ctx_.rules)
187 , consequences(result.second)
188 , flags(ctx_.flags)
189 , j(ctx_.j)
190 , ter(result.first)
191 {
192 }
193
197 operator=(PreflightResult const&) = delete;
198};
199
207{
208public:
212 STTx const& tx;
217
219 TER const ter;
223
225 template <class Context>
226 PreclaimResult(Context const& ctx_, TER ter_)
227 : view(ctx_.view)
228 , tx(ctx_.tx)
229 , flags(ctx_.flags)
230 , j(ctx_.j)
231 , ter(ter_)
233 {
234 }
235
239 operator=(PreclaimResult const&) = delete;
240};
241
260 Application& app,
261 Rules const& rules,
262 STTx const& tx,
263 ApplyFlags flags,
265
296 PreflightResult const& preflightResult,
297 Application& app,
298 OpenView const& view);
299
317calculateBaseFee(ReadView const& view, STTx const& tx);
318
331calculateDefaultBaseFee(ReadView const& view, STTx const& tx);
332
350doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view);
351
352} // namespace ripple
353
354#endif
A generic endpoint for log messages.
Definition: Journal.h:60
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:57
A view into a ledger.
Definition: ReadView.h:52
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: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
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:303
ApplyResult doApply(PreclaimResult const &preclaimResult, Application &app, OpenView &view)
Apply a prechecked transaction to an OpenView.
Definition: applySteps.cpp:381
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
Definition: applySteps.cpp:369
PreclaimResult preclaim(PreflightResult const &preflightResult, Application &app, OpenView const &view)
Gate a transaction based on static ledger information.
Definition: applySteps.cpp:323
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:242
ApplyFlags
Definition: ApplyView.h:31
@ tapRETRY
Definition: ApplyView.h:40
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
Definition: applySteps.cpp:375
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:207
ApplyFlags const flags
From the input - the flags.
Definition: applySteps.h:214
TER const ter
Intermediate transaction result.
Definition: applySteps.h:219
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:222
ReadView const & view
From the input - the ledger view.
Definition: applySteps.h:210
PreclaimResult(Context const &ctx_, TER ter_)
Constructor.
Definition: applySteps.h:226
beast::Journal const j
From the input - the journal.
Definition: applySteps.h:216
PreclaimResult(PreclaimResult const &)=default
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:212
Describes the results of the preflight check.
Definition: applySteps.h:164
Rules const rules
From the input - the rules.
Definition: applySteps.h:169
PreflightResult & operator=(PreflightResult const &)=delete
Deleted copy assignment operator.
ApplyFlags const flags
From the input - the flags.
Definition: applySteps.h:173
PreflightResult(PreflightResult const &)=default
beast::Journal const j
From the input - the journal.
Definition: applySteps.h:175
NotTEC const ter
Intermediate transaction result.
Definition: applySteps.h:178
PreflightResult(Context const &ctx_, std::pair< NotTEC, TxConsequences > const &result)
Constructor.
Definition: applySteps.h:182
TxConsequences const consequences
Consequences of the transaction.
Definition: applySteps.h:171
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:167