rippled
Transactor.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_APP_TX_TRANSACTOR_H_INCLUDED
21 #define RIPPLE_APP_TX_TRANSACTOR_H_INCLUDED
22 
23 #include <ripple/app/tx/applySteps.h>
24 #include <ripple/app/tx/impl/ApplyContext.h>
25 #include <ripple/basics/XRPAmount.h>
26 #include <ripple/beast/utility/Journal.h>
27 #include <boost/optional.hpp>
28 
29 namespace ripple {
30 
33 {
34 public:
36  STTx const& tx;
37  Rules const rules;
40 
42  Application& app_,
43  STTx const& tx_,
44  Rules const& rules_,
45  ApplyFlags flags_,
46  beast::Journal j_);
47 
49  operator=(PreflightContext const&) = delete;
50 };
51 
54 {
55 public:
57  ReadView const& view;
59  STTx const& tx;
62 
64  Application& app_,
65  ReadView const& view_,
66  TER preflightResult_,
67  STTx const& tx_,
68  ApplyFlags flags_,
70  : app(app_)
71  , view(view_)
72  , preflightResult(preflightResult_)
73  , tx(tx_)
74  , flags(flags_)
75  , j(j_)
76  {
77  }
78 
80  operator=(PreclaimContext const&) = delete;
81 };
82 
83 struct TxConsequences;
84 struct PreflightResult;
85 
87 {
88 protected:
91 
93  XRPAmount mPriorBalance; // Balance before fees.
94  XRPAmount mSourceBalance; // Balance after fees.
95 
96  virtual ~Transactor() = default;
97  Transactor(Transactor const&) = delete;
98  Transactor&
99  operator=(Transactor const&) = delete;
100 
101 public:
104  operator()();
105 
106  ApplyView&
108  {
109  return ctx_.view();
110  }
111 
112  ApplyView const&
113  view() const
114  {
115  return ctx_.view();
116  }
117 
119  /*
120  These static functions are called from invoke_preclaim<Tx>
121  using name hiding to accomplish compile-time polymorphism,
122  so derived classes can override for different or extra
123  functionality. Use with care, as these are not really
124  virtual and so don't have the compiler-time protection that
125  comes with it.
126  */
127 
128  static NotTEC
129  checkSeq(PreclaimContext const& ctx);
130 
131  static TER
132  checkFee(PreclaimContext const& ctx, FeeUnit64 baseFee);
133 
134  static NotTEC
135  checkSign(PreclaimContext const& ctx);
136 
137  // Returns the fee in fee units, not scaled for load.
138  static FeeUnit64
139  calculateBaseFee(ReadView const& view, STTx const& tx);
140 
141  static bool
143  {
144  return false;
145  }
146 
147  static XRPAmount
148  calculateFeePaid(STTx const& tx);
149 
150  static XRPAmount
151  calculateMaxSpend(STTx const& tx);
152 
153  static TER
155  {
156  // Most transactors do nothing
157  // after checkSeq/Fee/Sign.
158  return tesSUCCESS;
159  }
161 
162 protected:
163  TER
164  apply();
165 
166  explicit Transactor(ApplyContext& ctx);
167 
168  virtual void
169  preCompute();
170 
171  virtual TER
172  doApply() = 0;
173 
183  static XRPAmount
184  minimumFee(
185  Application& app,
186  FeeUnit64 baseFee,
187  Fees const& fees,
188  ApplyFlags flags);
189 
190 private:
191  XRPAmount
192  reset(XRPAmount fee);
193 
194  void
195  setSeq();
196  TER
197  payFee();
198  static NotTEC
199  checkSingleSign(PreclaimContext const& ctx);
200  static NotTEC
201  checkMultiSign(PreclaimContext const& ctx);
202 };
203 
205 NotTEC
206 preflight0(PreflightContext const& ctx);
207 
209 NotTEC
210 preflight1(PreflightContext const& ctx);
211 
213 NotTEC
214 preflight2(PreflightContext const& ctx);
215 
216 } // namespace ripple
217 
218 #endif
ripple::Transactor::calculateMaxSpend
static XRPAmount calculateMaxSpend(STTx const &tx)
Definition: Transactor.cpp:155
ripple::Application
Definition: Application.h:97
ripple::preflight2
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:90
ripple::Transactor::affectsSubsequentTransactionAuth
static bool affectsSubsequentTransactionAuth(STTx const &tx)
Definition: Transactor.h:142
ripple::Transactor::checkMultiSign
static NotTEC checkMultiSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:413
ripple::PreclaimContext::view
ReadView const & view
Definition: Transactor.h:57
ripple::PreclaimContext::app
Application & app
Definition: Transactor.h:56
ripple::PreclaimContext::j
const beast::Journal j
Definition: Transactor.h:61
ripple::PreclaimContext::PreclaimContext
PreclaimContext(Application &app_, ReadView const &view_, TER preflightResult_, STTx const &tx_, ApplyFlags flags_, beast::Journal j_=beast::Journal{beast::Journal::getNullSink()})
Definition: Transactor.h:63
ripple::Transactor
Definition: Transactor.h:86
ripple::Transactor::j_
const beast::Journal j_
Definition: Transactor.h:90
ripple::Transactor::checkSingleSign
static NotTEC checkSingleSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:339
ripple::Transactor::view
ApplyView const & view() const
Definition: Transactor.h:113
std::pair
ripple::Transactor::operator()
std::pair< TER, bool > operator()()
Process the transaction.
Definition: Transactor.cpp:627
ripple::Transactor::reset
XRPAmount reset(XRPAmount fee)
Reset the context, discarding any changes made and adjust the fee.
Definition: Transactor.cpp:594
ripple::Transactor::operator=
Transactor & operator=(Transactor const &)=delete
ripple::ApplyFlags
ApplyFlags
Definition: ApplyView.h:30
ripple::PreflightContext::j
const beast::Journal j
Definition: Transactor.h:39
ripple::Transactor::minimumFee
static XRPAmount minimumFee(Application &app, FeeUnit64 baseFee, Fees const &fees, ApplyFlags flags)
Compute the minimum fee required to process a transaction with a given baseFee based on the current s...
Definition: Transactor.cpp:145
beast::Journal::getNullSink
static Sink & getNullSink()
Returns a Sink which does nothing.
Definition: beast_Journal.cpp:72
ripple::Transactor::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition: Transactor.h:154
ripple::preflight1
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:56
ripple::ApplyView
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:140
ripple::Transactor::doApply
virtual TER doApply()=0
ripple::Transactor::setSeq
void setSeq()
Definition: Transactor.cpp:275
ripple::base_uint< 160, detail::AccountIDTag >
ripple::preflight0
NotTEC preflight0(PreflightContext const &ctx)
Performs early sanity checks on the txid.
Definition: Transactor.cpp:40
ripple::Transactor::checkSign
static NotTEC checkSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:329
ripple::Fees
Reflects the fee settings for a particular ledger.
Definition: ReadView.h:47
ripple::PreclaimContext::operator=
PreclaimContext & operator=(PreclaimContext const &)=delete
ripple::Transactor::payFee
TER payFee()
Definition: Transactor.cpp:207
ripple::Transactor::apply
TER apply()
Definition: Transactor.cpp:298
ripple::TERSubset< CanCvtToTER >
ripple::PreflightContext::app
Application & app
Definition: Transactor.h:35
ripple::STTx
Definition: STTx.h:42
ripple::Transactor::calculateBaseFee
static FeeUnit64 calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:121
ripple::ApplyContext
State information when applying a tx.
Definition: ApplyContext.h:35
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::feeunit::TaggedFee
Definition: FeeUnits.h:70
ripple::ApplyContext::view
ApplyView & view()
Definition: ApplyContext.h:54
ripple::Transactor::Transactor
Transactor(Transactor const &)=delete
ripple::PreclaimContext::tx
STTx const & tx
Definition: Transactor.h:59
ripple::PreflightContext::PreflightContext
PreflightContext(Application &app_, STTx const &tx_, Rules const &rules_, ApplyFlags flags_, beast::Journal j_)
Definition: Transactor.cpp:104
ripple::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:53
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::PreflightContext::flags
ApplyFlags flags
Definition: Transactor.h:38
ripple::Transactor::view
ApplyView & view()
Definition: Transactor.h:107
ripple::PreclaimContext::preflightResult
TER preflightResult
Definition: Transactor.h:58
ripple::Transactor::mPriorBalance
XRPAmount mPriorBalance
Definition: Transactor.h:93
ripple::Transactor::mSourceBalance
XRPAmount mSourceBalance
Definition: Transactor.h:94
ripple::PreclaimContext::flags
ApplyFlags flags
Definition: Transactor.h:60
ripple::Transactor::~Transactor
virtual ~Transactor()=default
ripple::Rules
Rules controlling protocol behavior.
Definition: ReadView.h:127
ripple::Transactor::ctx_
ApplyContext & ctx_
Definition: Transactor.h:89
ripple::Transactor::account_
AccountID account_
Definition: Transactor.h:92
ripple::Transactor::checkSeq
static NotTEC checkSeq(PreclaimContext const &ctx)
Definition: Transactor.cpp:227
ripple::PreflightContext::tx
STTx const & tx
Definition: Transactor.h:36
ripple::PreflightContext
State information when preflighting a tx.
Definition: Transactor.h:32
ripple::Transactor::calculateFeePaid
static XRPAmount calculateFeePaid(STTx const &tx)
Definition: Transactor.cpp:139
ripple::PreflightContext::operator=
PreflightContext & operator=(PreflightContext const &)=delete
ripple::PreflightContext::rules
const Rules rules
Definition: Transactor.h:37
ripple::Transactor::checkFee
static TER checkFee(PreclaimContext const &ctx, FeeUnit64 baseFee)
Definition: Transactor.cpp:161
ripple::tesSUCCESS
@ tesSUCCESS
Definition: TER.h:213
ripple::Transactor::preCompute
virtual void preCompute()
Definition: Transactor.cpp:291
ripple::XRPAmount
Definition: XRPAmount.h:46
ripple::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:507