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 class TxQ;
31 
35 inline bool
37 {
38  return isTecClaim(ter) && !(flags & tapRETRY);
39 }
40 
46 {
47 public:
50  enum Category {
52  normal = 0,
56  };
57 
58 private:
61  bool isBlocker_;
70 
71 public:
72  // Constructor if preflight returns a value other than tesSUCCESS.
73  // Asserts if tesSUCCESS is passed.
74  explicit TxConsequences(NotTEC pfresult);
75 
77  explicit TxConsequences(STTx const& tx);
78 
80  TxConsequences(STTx const& tx, Category category);
81 
84 
87 
89  TxConsequences(TxConsequences const&) = default;
92  operator=(TxConsequences const&) = default;
94  TxConsequences(TxConsequences&&) = default;
97  operator=(TxConsequences&&) = default;
98 
100  XRPAmount
101  fee() const
102  {
103  return fee_;
104  }
105 
107  XRPAmount const&
109  {
110  return potentialSpend_;
111  }
112 
114  SeqProxy
115  seqProxy() const
116  {
117  return seqProx_;
118  }
119 
123  {
124  return sequencesConsumed_;
125  }
126 
128  bool
129  isBlocker() const
130  {
131  return isBlocker_;
132  }
133 
134  // Return the SeqProxy that would follow this.
135  SeqProxy
136  followingSeq() const
137  {
138  SeqProxy following = seqProx_;
139  following.advanceBy(sequencesConsumed());
140  return following;
141  }
142 };
143 
151 {
152 public:
154  STTx const& tx;
156  Rules const rules;
163 
165  NotTEC const ter;
166 
168  template <class Context>
170  Context const& ctx_,
171  std::pair<NotTEC, TxConsequences> const& result)
172  : tx(ctx_.tx)
173  , rules(ctx_.rules)
174  , consequences(result.second)
175  , flags(ctx_.flags)
176  , j(ctx_.j)
177  , ter(result.first)
178  {
179  }
180 
181  PreflightResult(PreflightResult const&) = default;
184  operator=(PreflightResult const&) = delete;
185 };
186 
194 {
195 public:
197  ReadView const& view;
199  STTx const& tx;
204 
206  TER const ter;
209  bool const likelyToClaimFee;
210 
212  template <class Context>
213  PreclaimResult(Context const& ctx_, TER ter_)
214  : view(ctx_.view)
215  , tx(ctx_.tx)
216  , flags(ctx_.flags)
217  , j(ctx_.j)
218  , ter(ter_)
220  {
221  }
222 
223  PreclaimResult(PreclaimResult const&) = default;
226  operator=(PreclaimResult const&) = delete;
227 };
228 
245 PreflightResult
246 preflight(
247  Application& app,
248  Rules const& rules,
249  STTx const& tx,
250  ApplyFlags flags,
251  beast::Journal j);
252 
281 PreclaimResult
282 preclaim(
283  PreflightResult const& preflightResult,
284  Application& app,
285  OpenView const& view);
286 
303 XRPAmount
304 calculateBaseFee(ReadView const& view, STTx const& tx);
305 
317 XRPAmount
318 calculateDefaultBaseFee(ReadView const& view, STTx const& tx);
319 
337 doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view);
338 
339 } // namespace ripple
340 
341 #endif
ripple::TxConsequences::fee
XRPAmount fee() const
Fee.
Definition: applySteps.h:101
ripple::PreclaimResult::view
ReadView const & view
From the input - the ledger view.
Definition: applySteps.h:197
ripple::PreflightResult::consequences
const TxConsequences consequences
Consequences of the transaction.
Definition: applySteps.h:158
ripple::PreclaimResult::j
const beast::Journal j
From the input - the journal.
Definition: applySteps.h:203
ripple::TxConsequences::TxConsequences
TxConsequences(NotTEC pfresult)
Definition: applySteps.cpp:320
std::pair
ripple::PreflightResult::operator=
PreflightResult & operator=(PreflightResult const &)=delete
Deleted copy assignment operator.
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:29
ripple::TxConsequences::Category
Category
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:50
ripple::TxConsequences::fee_
XRPAmount fee_
Transaction fee.
Definition: applySteps.h:63
ripple::PreflightResult::tx
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:154
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:473
ripple::PreclaimResult::likelyToClaimFee
const bool likelyToClaimFee
Success flag - whether the transaction is likely to claim a fee.
Definition: applySteps.h:209
ripple::isTecClaim
bool isTecClaim(TER x)
Definition: TER.h:603
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:206
ripple::PreflightResult::PreflightResult
PreflightResult(Context const &ctx_, std::pair< NotTEC, TxConsequences > const &result)
Constructor.
Definition: applySteps.h:169
ripple::doApply
std::pair< TER, bool > doApply(PreclaimResult const &preclaimResult, Application &app, OpenView &view)
Apply a prechecked transaction to an OpenView.
Definition: applySteps.cpp:551
ripple::PreflightResult
Describes the results of the preflight check.
Definition: applySteps.h:150
ripple::TxConsequences::potentialSpend
XRPAmount const & potentialSpend() const
Potential Spend.
Definition: applySteps.h:108
ripple::PreflightResult::rules
const Rules rules
From the input - the rules.
Definition: applySteps.h:156
ripple::TxConsequences::blocker
@ blocker
Affects the ability of subsequent transactions to claim a fee.
Definition: applySteps.h:55
ripple::PreflightResult::ter
const NotTEC ter
Intermediate transaction result.
Definition: applySteps.h:165
ripple::TERSubset< CanCvtToTER >
ripple::TxConsequences::isBlocker
bool isBlocker() const
Returns true if the transaction is a blocker.
Definition: applySteps.h:129
ripple::TxConsequences::seqProx_
SeqProxy seqProx_
SeqProxy of transaction.
Definition: applySteps.h:67
ripple::STTx
Definition: STTx.h:45
ripple::SeqProxy::advanceBy
SeqProxy & advanceBy(std::uint32_t amount)
Definition: SeqProxy.h:104
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::TxConsequences::isBlocker_
bool isBlocker_
Describes how the transaction affects subsequent transactions.
Definition: applySteps.h:61
ripple::calculateDefaultBaseFee
XRPAmount calculateDefaultBaseFee(ReadView const &view, STTx const &tx)
Return the minimum fee that an "ordinary" transaction would pay.
Definition: applySteps.cpp:545
ripple::tapRETRY
@ tapRETRY
Definition: ApplyView.h:38
ripple::preclaim
PreclaimResult preclaim(PreflightResult const &preflightResult, Application &app, OpenView const &view)
Gate a transaction based on static ledger information.
Definition: applySteps.cpp:493
ripple::TxConsequences::sequencesConsumed
std::uint32_t sequencesConsumed() const
Sequences consumed.
Definition: applySteps.h:122
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::PreclaimResult::operator=
PreclaimResult & operator=(PreclaimResult const &)=delete
Deleted copy assignment operator.
ripple::TxConsequences::operator=
TxConsequences & operator=(TxConsequences const &)=default
Copy assignment operator.
ripple::TxConsequences::seqProxy
SeqProxy seqProxy() const
SeqProxy.
Definition: applySteps.h:115
ripple::PreclaimResult
Describes the results of the preclaim check.
Definition: applySteps.h:193
ripple::SeqProxy
A type that represents either a sequence value or a ticket value.
Definition: SeqProxy.h:55
ripple::TxConsequences::potentialSpend_
XRPAmount potentialSpend_
Does NOT include the fee.
Definition: applySteps.h:65
ripple::Rules
Rules controlling protocol behavior.
Definition: Rules.h:33
ripple::calculateBaseFee
XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Compute only the expected base fee for a transaction.
Definition: applySteps.cpp:539
ripple::PreclaimResult::flags
const ApplyFlags flags
From the input - the flags.
Definition: applySteps.h:201
ripple::TxConsequences::normal
@ normal
Moves currency around, creates offers, etc.
Definition: applySteps.h:52
ripple::PreflightResult::flags
const ApplyFlags flags
From the input - the flags.
Definition: applySteps.h:160
ripple::TxConsequences::sequencesConsumed_
std::uint32_t sequencesConsumed_
Number of sequences consumed.
Definition: applySteps.h:69
ripple::PreclaimResult::PreclaimResult
PreclaimResult(Context const &ctx_, TER ter_)
Constructor.
Definition: applySteps.h:213
ripple::TxConsequences
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition: applySteps.h:45
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:222
ripple::TxConsequences::followingSeq
SeqProxy followingSeq() const
Definition: applySteps.h:136
ripple::PreclaimResult::tx
STTx const & tx
From the input - the transaction.
Definition: applySteps.h:199
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::PreflightResult::j
const beast::Journal j
From the input - the journal.
Definition: applySteps.h:162