rippled
Loading...
Searching...
No Matches
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 <xrpld/app/tx/applySteps.h>
24#include <xrpld/app/tx/detail/ApplyContext.h>
25#include <xrpl/beast/utility/Journal.h>
26#include <xrpl/protocol/XRPAmount.h>
27
28namespace ripple {
29
32{
33public:
35 STTx const& tx;
36 Rules const rules;
39
41 Application& app_,
42 STTx const& tx_,
43 Rules const& rules_,
44 ApplyFlags flags_,
46
48 operator=(PreflightContext const&) = delete;
49};
50
53{
54public:
56 ReadView const& view;
58 STTx const& tx;
61
63 Application& app_,
64 ReadView const& view_,
65 TER preflightResult_,
66 STTx const& tx_,
67 ApplyFlags flags_,
69 : app(app_)
70 , view(view_)
71 , preflightResult(preflightResult_)
72 , tx(tx_)
73 , flags(flags_)
74 , j(j_)
75 {
76 }
77
78 PreclaimContext&
79 operator=(PreclaimContext const&) = delete;
80};
81
82class TxConsequences;
83struct PreflightResult;
84
86{
87protected:
90
92 XRPAmount mPriorBalance; // Balance before fees.
93 XRPAmount mSourceBalance; // Balance after fees.
94
95 virtual ~Transactor() = default;
96 Transactor(Transactor const&) = delete;
98 operator=(Transactor const&) = delete;
99
100public:
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 checkSeqProxy(ReadView const& view, STTx const& tx, beast::Journal j);
130
131 static NotTEC
133
134 static TER
135 checkFee(PreclaimContext const& ctx, XRPAmount baseFee);
136
137 static NotTEC
138 checkSign(PreclaimContext const& ctx);
139
140 // Returns the fee in fee units, not scaled for load.
141 static XRPAmount
142 calculateBaseFee(ReadView const& view, STTx const& tx);
143
144 static TER
146 {
147 // Most transactors do nothing
148 // after checkSeq/Fee/Sign.
149 return tesSUCCESS;
150 }
152
153 // Interface used by DeleteAccount
154 static TER
157 AccountID const& account,
158 uint256 const& ticketIndex,
160
161protected:
162 TER
163 apply();
164
165 explicit Transactor(ApplyContext& ctx);
166
167 virtual void
168 preCompute();
169
170 virtual TER
171 doApply() = 0;
172
182 static XRPAmount
184 Application& app,
185 XRPAmount baseFee,
186 Fees const& fees,
187 ApplyFlags flags);
188
189private:
191 reset(XRPAmount fee);
192
193 TER
194 consumeSeqProxy(SLE::pointer const& sleAccount);
195 TER
196 payFee();
197 static NotTEC
199 static NotTEC
201
202 void trapTransaction(uint256) const;
203};
204
206NotTEC
207preflight0(PreflightContext const& ctx);
208
210NotTEC
211preflight1(PreflightContext const& ctx);
212
214NotTEC
215preflight2(PreflightContext const& ctx);
216
217} // namespace ripple
218
219#endif
A generic endpoint for log messages.
Definition: Journal.h:59
static Sink & getNullSink()
Returns a Sink which does nothing.
State information when applying a tx.
Definition: ApplyContext.h:36
ApplyView & view()
Definition: ApplyContext.h:54
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:140
A view into a ledger.
Definition: ReadView.h:55
Rules controlling protocol behavior.
Definition: Rules.h:35
TER consumeSeqProxy(SLE::pointer const &sleAccount)
Definition: Transactor.cpp:397
ApplyResult operator()()
Process the transaction.
Definition: Transactor.cpp:912
Transactor & operator=(Transactor const &)=delete
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
Definition: Transactor.cpp:367
static TER checkFee(PreclaimContext const &ctx, XRPAmount baseFee)
Definition: Transactor.cpp:222
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:194
static NotTEC checkSeqProxy(ReadView const &view, STTx const &tx, beast::Journal j)
Definition: Transactor.cpp:295
static NotTEC checkSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:515
void trapTransaction(uint256) const
Definition: Transactor.cpp:905
static XRPAmount minimumFee(Application &app, XRPAmount 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:212
virtual ~Transactor()=default
static NotTEC checkSingleSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:533
AccountID const account_
Definition: Transactor.h:91
ApplyView & view()
Definition: Transactor.h:107
static TER preclaim(PreclaimContext const &ctx)
Definition: Transactor.h:145
beast::Journal const j_
Definition: Transactor.h:89
XRPAmount mPriorBalance
Definition: Transactor.h:92
virtual void preCompute()
Definition: Transactor.cpp:470
static TER ticketDelete(ApplyView &view, AccountID const &account, uint256 const &ticketIndex, beast::Journal j)
Definition: Transactor.cpp:416
XRPAmount mSourceBalance
Definition: Transactor.h:93
ApplyContext & ctx_
Definition: Transactor.h:88
virtual TER doApply()=0
std::pair< TER, XRPAmount > reset(XRPAmount fee)
Reset the context, discarding any changes made and adjust the fee.
Definition: Transactor.cpp:862
Transactor(Transactor const &)=delete
ApplyView const & view() const
Definition: Transactor.h:113
static NotTEC checkMultiSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:613
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition: applySteps.h:58
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
NotTEC preflight0(PreflightContext const &ctx)
Performs early sanity checks on the txid.
Definition: Transactor.cpp:42
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:82
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:134
@ tesSUCCESS
Definition: TER.h:242
ApplyFlags
Definition: ApplyView.h:30
Reflects the fee settings for a particular ledger.
Definition: protocol/Fees.h:33
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:53
ReadView const & view
Definition: Transactor.h:56
PreclaimContext & operator=(PreclaimContext const &)=delete
PreclaimContext(Application &app_, ReadView const &view_, TER preflightResult_, STTx const &tx_, ApplyFlags flags_, beast::Journal j_=beast::Journal{beast::Journal::getNullSink()})
Definition: Transactor.h:62
Application & app
Definition: Transactor.h:55
beast::Journal const j
Definition: Transactor.h:60
State information when preflighting a tx.
Definition: Transactor.h:32
beast::Journal const j
Definition: Transactor.h:38
PreflightContext & operator=(PreflightContext const &)=delete
Describes the results of the preflight check.
Definition: applySteps.h:163