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/beast/utility/Journal.h>
24 #include <ripple/ledger/ApplyViewImpl.h>
25 
26 namespace ripple {
27 
28 class Application;
29 class STTx;
30 
34 inline bool
36 {
37  return isTecClaim(ter) && !(flags & tapRETRY);
38 }
39 
47 {
48 public:
50  STTx const& tx;
52  Rules const rules;
57 
59  NotTEC const ter;
60 
62  template <class Context>
63  PreflightResult(Context const& ctx_, NotTEC ter_)
64  : tx(ctx_.tx)
65  , rules(ctx_.rules)
66  , flags(ctx_.flags)
67  , j(ctx_.j)
68  , ter(ter_)
69  {
70  }
71 
72  PreflightResult(PreflightResult const&) = default;
75  operator=(PreflightResult const&) = delete;
76 };
77 
85 {
86 public:
88  ReadView const& view;
90  STTx const& tx;
95 
97  TER const ter;
100  bool const likelyToClaimFee;
101 
103  template <class Context>
104  PreclaimResult(Context const& ctx_, TER ter_)
105  : view(ctx_.view)
106  , tx(ctx_.tx)
107  , flags(ctx_.flags)
108  , j(ctx_.j)
109  , ter(ter_)
111  {
112  }
113 
114  PreclaimResult(PreclaimResult const&) = default;
117  operator=(PreclaimResult const&) = delete;
118 };
119 
127 {
132  normal = 0,
136  };
137 
142  XRPAmount const fee;
145 
148  ConsequenceCategory const category_,
149  XRPAmount const fee_,
150  XRPAmount const spend_)
151  : category(category_), fee(fee_), potentialSpend(spend_)
152  {
153  }
154 
156  TxConsequences(TxConsequences const&) = default;
159  operator=(TxConsequences const&) = delete;
161  TxConsequences(TxConsequences&&) = default;
164  operator=(TxConsequences&&) = delete;
165 };
166 
183 PreflightResult
184 preflight(
185  Application& app,
186  Rules const& rules,
187  STTx const& tx,
188  ApplyFlags flags,
189  beast::Journal j);
190 
219 PreclaimResult
220 preclaim(
221  PreflightResult const& preflightResult,
222  Application& app,
223  OpenView const& view);
224 
241 FeeUnit64
242 calculateBaseFee(ReadView const& view, STTx const& tx);
243 
259 TxConsequences
260 calculateConsequences(PreflightResult const& preflightResult);
261 
279 doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view);
280 
281 } // namespace ripple
282 
283 #endif
ripple::PreclaimResult::view
ReadView const & view
From the input - the ledger view.
Definition: applySteps.h:88
ripple::PreclaimResult::j
const beast::Journal j
From the input - the journal.
Definition: applySteps.h:94
ripple::calculateBaseFee
FeeUnit64 calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
Definition: applySteps.cpp:475
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:126
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:132
ripple::TxConsequences::ConsequenceCategory
ConsequenceCategory
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:130
ripple::PreflightResult::tx
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:50
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:409
ripple::PreclaimResult::likelyToClaimFee
const bool likelyToClaimFee
Success flag - whether the transaction is likely to claim a fee.
Definition: applySteps.h:100
ripple::isTecClaim
bool isTecClaim(TER x)
Definition: TER.h:582
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:35
ripple::PreclaimResult::ter
const TER ter
Intermediate transaction result.
Definition: applySteps.h:97
ripple::TxConsequences::potentialSpend
const XRPAmount potentialSpend
Does NOT include the fee.
Definition: applySteps.h:144
ripple::doApply
std::pair< TER, bool > doApply(PreclaimResult const &preclaimResult, Application &app, OpenView &view)
Apply a prechecked transaction to an OpenView.
Definition: applySteps.cpp:493
ripple::PreflightResult
Describes the results of the preflight check.
Definition: applySteps.h:46
ripple::PreflightResult::rules
const Rules rules
From the input - the rules.
Definition: applySteps.h:52
ripple::PreflightResult::ter
const NotTEC ter
Intermediate transaction result.
Definition: applySteps.h:59
ripple::TERSubset< CanCvtToTER >
ripple::STTx
Definition: STTx.h:42
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::TxConsequences::TxConsequences
TxConsequences(ConsequenceCategory const category_, XRPAmount const fee_, XRPAmount const spend_)
Constructor.
Definition: applySteps.h:147
ripple::tapRETRY
@ tapRETRY
Definition: ApplyView.h:39
ripple::preclaim
PreclaimResult preclaim(PreflightResult const &preflightResult, Application &app, OpenView const &view)
Gate a transaction based on static ledger information.
Definition: applySteps.cpp:429
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:188
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:63
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:481
ripple::FeeUnit64
FeeUnit< std::uint64_t > FeeUnit64
Definition: FeeUnits.h:460
ripple::PreclaimResult
Describes the results of the preclaim check.
Definition: applySteps.h:84
ripple::TxConsequences::fee
const XRPAmount fee
Transaction fee.
Definition: applySteps.h:142
ripple::Rules
Rules controlling protocol behavior.
Definition: ReadView.h:127
ripple::PreclaimResult::flags
const ApplyFlags flags
From the input - the flags.
Definition: applySteps.h:92
ripple::PreflightResult::flags
const ApplyFlags flags
From the input - the flags.
Definition: applySteps.h:54
ripple::PreclaimResult::PreclaimResult
PreclaimResult(Context const &ctx_, TER ter_)
Constructor.
Definition: applySteps.h:104
ripple::TxConsequences::category
const ConsequenceCategory category
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:140
ripple::TxConsequences::blocker
@ blocker
Affects the ability of subsequent transactions to claim a fee.
Definition: applySteps.h:135
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:213
ripple::PreclaimResult::tx
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:90
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::PreflightResult::j
const beast::Journal j
From the input - the journal.
Definition: applySteps.h:56