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
26#include <xrpl/beast/utility/Journal.h>
27#include <xrpl/protocol/XRPAmount.h>
28
29namespace ripple {
30
33{
34public:
36 STTx const& tx;
37 Rules const rules;
40
42 Application& app_,
43 STTx const& tx_,
44 Rules const& rules_,
45 ApplyFlags flags_,
47
49 operator=(PreflightContext const&) = delete;
50};
51
54{
55public:
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
79 PreclaimContext&
80 operator=(PreclaimContext const&) = delete;
81};
82
83class TxConsequences;
84struct PreflightResult;
85
87{
88protected:
91
93 XRPAmount mPriorBalance; // Balance before fees.
94 XRPAmount mSourceBalance; // Balance after fees.
95
96 virtual ~Transactor() = default;
97 Transactor(Transactor const&) = delete;
99 operator=(Transactor const&) = delete;
100
101public:
105 operator()();
106
107 ApplyView&
109 {
110 return ctx_.view();
111 }
112
113 ApplyView const&
114 view() const
115 {
116 return ctx_.view();
117 }
118
120 /*
121 These static functions are called from invoke_preclaim<Tx>
122 using name hiding to accomplish compile-time polymorphism,
123 so derived classes can override for different or extra
124 functionality. Use with care, as these are not really
125 virtual and so don't have the compiler-time protection that
126 comes with it.
127 */
128
129 static NotTEC
130 checkSeqProxy(ReadView const& view, STTx const& tx, beast::Journal j);
131
132 static NotTEC
134
135 static TER
136 checkFee(PreclaimContext const& ctx, XRPAmount baseFee);
137
138 static NotTEC
139 checkSign(PreclaimContext const& ctx);
140
141 // Returns the fee in fee units, not scaled for load.
142 static XRPAmount
143 calculateBaseFee(ReadView const& view, STTx const& tx);
144
145 static TER
147 {
148 // Most transactors do nothing
149 // after checkSeq/Fee/Sign.
150 return tesSUCCESS;
151 }
153
154 // Interface used by DeleteAccount
155 static TER
158 AccountID const& account,
159 uint256 const& ticketIndex,
161
162protected:
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
185 Application& app,
186 XRPAmount baseFee,
187 Fees const& fees,
188 ApplyFlags flags);
189
190private:
192 reset(XRPAmount fee);
193
194 TER
195 consumeSeqProxy(SLE::pointer const& sleAccount);
196 TER
197 payFee();
198 static NotTEC
200 static NotTEC
202
203 void trapTransaction(uint256) const;
204};
205
207NotTEC
208preflight0(PreflightContext const& ctx);
209
211NotTEC
212preflight1(PreflightContext const& ctx);
213
215NotTEC
216preflight2(PreflightContext const& ctx);
217
218} // namespace ripple
219
220#endif
A generic endpoint for log messages.
Definition: Journal.h:60
static Sink & getNullSink()
Returns a Sink which does nothing.
State information when applying a tx.
Definition: ApplyContext.h:37
ApplyView & view()
Definition: ApplyContext.h:55
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:141
A view into a ledger.
Definition: ReadView.h:52
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:92
ApplyView & view()
Definition: Transactor.h:108
static TER preclaim(PreclaimContext const &ctx)
Definition: Transactor.h:146
beast::Journal const j_
Definition: Transactor.h:90
XRPAmount mPriorBalance
Definition: Transactor.h:93
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:94
ApplyContext & ctx_
Definition: Transactor.h:89
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:114
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:59
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:31
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:54
ReadView const & view
Definition: Transactor.h:57
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:63
Application & app
Definition: Transactor.h:56
beast::Journal const j
Definition: Transactor.h:61
State information when preflighting a tx.
Definition: Transactor.h:33
beast::Journal const j
Definition: Transactor.h:39
PreflightContext & operator=(PreflightContext const &)=delete
Describes the results of the preflight check.
Definition: applySteps.h:164