rippled
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 <ripple/ledger/ApplyViewImpl.h>
24 #include <ripple/beast/utility/Journal.h>
25 
26 namespace ripple {
27 
28 class Application;
29 class STTx;
30 
34 inline
35 bool
37 {
38  return isTecClaim(ter) && !(flags & tapRETRY);
39 }
40 
48 {
49 public:
51  STTx const& tx;
53  Rules const rules;
58 
60  NotTEC const ter;
61 
63  template<class Context>
64  PreflightResult(Context const& ctx_,
65  NotTEC ter_)
66  : tx(ctx_.tx)
67  , rules(ctx_.rules)
68  , flags(ctx_.flags)
69  , j(ctx_.j)
70  , ter(ter_)
71  {
72  }
73 
74  PreflightResult(PreflightResult const&) = default;
76  PreflightResult& operator=(PreflightResult const&) = delete;
77 };
78 
86 {
87 public:
89  ReadView const& view;
91  STTx const& tx;
96 
98  TER const ter;
101  bool const likelyToClaimFee;
102 
104  template<class Context>
105  PreclaimResult(Context const& ctx_, TER ter_)
106  : view(ctx_.view)
107  , tx(ctx_.tx)
108  , flags(ctx_.flags)
109  , j(ctx_.j)
110  , ter(ter_)
113  {
114  }
115 
116  PreclaimResult(PreclaimResult const&) = default;
118  PreclaimResult& operator=(PreclaimResult const&) = delete;
119 };
120 
128 {
132  {
134  normal = 0,
138  };
139 
144  XRPAmount const fee;
147 
150  XRPAmount const fee_, XRPAmount const spend_)
151  : category(category_)
152  , fee(fee_)
153  , potentialSpend(spend_)
154  {
155  }
156 
158  TxConsequences(TxConsequences const&) = default;
160  TxConsequences& operator=(TxConsequences const&) = delete;
162  TxConsequences(TxConsequences&&) = default;
165 
166 };
167 
184 PreflightResult
185 preflight(Application& app, Rules const& rules,
186  STTx const& tx, ApplyFlags flags,
187  beast::Journal j);
188 
217 PreclaimResult
218 preclaim(PreflightResult const& preflightResult,
219  Application& app, OpenView const& view);
220 
237 FeeUnit64
238 calculateBaseFee(ReadView const& view,
239  STTx const& tx);
240 
256 TxConsequences
257 calculateConsequences(PreflightResult const& preflightResult);
258 
276 doApply(PreclaimResult const& preclaimResult,
277  Application& app, OpenView& view);
278 
279 }
280 
281 #endif
ripple::PreclaimResult::view
ReadView const & view
From the input - the ledger view.
Definition: applySteps.h:89
ripple::PreclaimResult::j
const beast::Journal j
From the input - the journal.
Definition: applySteps.h:95
ripple::calculateBaseFee
FeeUnit64 calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
Definition: applySteps.cpp:318
std::pair
ripple::PreflightResult::operator=
PreflightResult & operator=(PreflightResult const &)=delete
Deleted copy assignment operator.
ripple::TxConsequences
Structure describing the consequences to the account of applying a transaction if the transaction con...
Definition: applySteps.h:127
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:30
ripple::TxConsequences::operator=
TxConsequences & operator=(TxConsequences const &)=delete
Deleted copy assignment operator.
ripple::TxConsequences::normal
@ normal
Moves currency around, creates offers, etc.
Definition: applySteps.h:134
ripple::TxConsequences::ConsequenceCategory
ConsequenceCategory
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:131
ripple::PreflightResult::tx
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:51
ripple::preflight
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:266
ripple::PreclaimResult::likelyToClaimFee
const bool likelyToClaimFee
Success flag - whether the transaction is likely to claim a fee.
Definition: applySteps.h:101
ripple::isTecClaim
bool isTecClaim(TER x)
Definition: TER.h:506
ripple::isTecClaimHardFail
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:36
ripple::PreclaimResult::ter
const TER ter
Intermediate transaction result.
Definition: applySteps.h:98
ripple::TxConsequences::potentialSpend
const XRPAmount potentialSpend
Does NOT include the fee.
Definition: applySteps.h:146
ripple::doApply
std::pair< TER, bool > doApply(PreclaimResult const &preclaimResult, Application &app, OpenView &view)
Apply a prechecked transaction to an OpenView.
Definition: applySteps.cpp:336
ripple::PreflightResult
Describes the results of the preflight check.
Definition: applySteps.h:47
ripple::PreflightResult::rules
const Rules rules
From the input - the rules.
Definition: applySteps.h:53
ripple::PreflightResult::ter
const NotTEC ter
Intermediate transaction result.
Definition: applySteps.h:60
ripple::TERSubset< CanCvtToTER >
ripple::STTx
Definition: STTx.h:43
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
ripple::TxConsequences::TxConsequences
TxConsequences(ConsequenceCategory const category_, XRPAmount const fee_, XRPAmount const spend_)
Constructor.
Definition: applySteps.h:149
ripple::tapRETRY
@ tapRETRY
Definition: ApplyView.h:41
ripple::preclaim
PreclaimResult preclaim(PreflightResult const &preflightResult, Application &app, OpenView const &view)
Gate a transaction based on static ledger information.
Definition: applySteps.cpp:285
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:186
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::PreflightResult::PreflightResult
PreflightResult(Context const &ctx_, NotTEC ter_)
Constructor.
Definition: applySteps.h:64
ripple::PreclaimResult::operator=
PreclaimResult & operator=(PreclaimResult const &)=delete
Deleted copy assignment operator.
ripple::calculateConsequences
TxConsequences calculateConsequences(PreflightResult const &preflightResult)
Determine the XRP balance consequences if a transaction consumes the maximum XRP allowed.
Definition: applySteps.cpp:325
ripple::FeeUnit64
FeeUnit< std::uint64_t > FeeUnit64
Definition: FeeUnits.h:477
ripple::PreclaimResult
Describes the results of the preclaim check.
Definition: applySteps.h:85
ripple::TxConsequences::fee
const XRPAmount fee
Transaction fee.
Definition: applySteps.h:144
ripple::Rules
Rules controlling protocol behavior.
Definition: ReadView.h:126
ripple::PreclaimResult::flags
const ApplyFlags flags
From the input - the flags.
Definition: applySteps.h:93
ripple::PreflightResult::flags
const ApplyFlags flags
From the input - the flags.
Definition: applySteps.h:55
ripple::PreclaimResult::PreclaimResult
PreclaimResult(Context const &ctx_, TER ter_)
Constructor.
Definition: applySteps.h:105
ripple::TxConsequences::category
const ConsequenceCategory category
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:142
ripple::TxConsequences::blocker
@ blocker
Affects the ability of subsequent transactions to claim a fee.
Definition: applySteps.h:137
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:219
ripple::PreclaimResult::tx
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:91
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::PreflightResult::j
const beast::Journal j
From the input - the journal.
Definition: applySteps.h:57