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/Permissions.h>
28#include <xrpl/protocol/XRPAmount.h>
29
30namespace ripple {
31
34{
35public:
37 STTx const& tx;
38 Rules const rules;
42
44 Application& app_,
45 STTx const& tx_,
46 uint256 parentBatchId_,
47 Rules const& rules_,
48 ApplyFlags flags_,
50 : app(app_)
51 , tx(tx_)
52 , rules(rules_)
53 , flags(flags_)
54 , parentBatchId(parentBatchId_)
55 , j(j_)
56 {
57 XRPL_ASSERT(
58 (flags_ & tapBATCH) == tapBATCH, "Batch apply flag should be set");
59 }
60
62 Application& app_,
63 STTx const& tx_,
64 Rules const& rules_,
65 ApplyFlags flags_,
67 : app(app_), tx(tx_), rules(rules_), flags(flags_), j(j_)
68 {
69 XRPL_ASSERT(
70 (flags_ & tapBATCH) == 0, "Batch apply flag should not be set");
71 }
72
73 PreflightContext&
74 operator=(PreflightContext const&) = delete;
75};
76
79{
80public:
82 ReadView const& view;
85 STTx const& tx;
88
90 Application& app_,
91 ReadView const& view_,
92 TER preflightResult_,
93 STTx const& tx_,
94 ApplyFlags flags_,
95 std::optional<uint256> parentBatchId_,
97 : app(app_)
98 , view(view_)
99 , preflightResult(preflightResult_)
100 , flags(flags_)
101 , tx(tx_)
102 , parentBatchId(parentBatchId_)
103 , j(j_)
104 {
105 XRPL_ASSERT(
106 parentBatchId.has_value() == ((flags_ & tapBATCH) == tapBATCH),
107 "Parent Batch ID should be set if batch apply flag is set");
108 }
109
111 Application& app_,
112 ReadView const& view_,
113 TER preflightResult_,
114 STTx const& tx_,
115 ApplyFlags flags_,
118 app_,
119 view_,
120 preflightResult_,
121 tx_,
122 flags_,
123 std::nullopt,
124 j_)
125 {
126 XRPL_ASSERT(
127 (flags_ & tapBATCH) == 0, "Batch apply flag should not be set");
128 }
129
130 PreclaimContext&
131 operator=(PreclaimContext const&) = delete;
132};
133
134class TxConsequences;
135struct PreflightResult;
136
138{
139protected:
142
144 XRPAmount mPriorBalance; // Balance before fees.
145 XRPAmount mSourceBalance; // Balance after fees.
146
147 virtual ~Transactor() = default;
148 Transactor(Transactor const&) = delete;
150 operator=(Transactor const&) = delete;
151
152public:
156 operator()();
157
158 ApplyView&
160 {
161 return ctx_.view();
162 }
163
164 ApplyView const&
165 view() const
166 {
167 return ctx_.view();
168 }
169
171 /*
172 These static functions are called from invoke_preclaim<Tx>
173 using name hiding to accomplish compile-time polymorphism,
174 so derived classes can override for different or extra
175 functionality. Use with care, as these are not really
176 virtual and so don't have the compiler-time protection that
177 comes with it.
178 */
179
180 static NotTEC
181 checkSeqProxy(ReadView const& view, STTx const& tx, beast::Journal j);
182
183 static NotTEC
185
186 static TER
187 checkFee(PreclaimContext const& ctx, XRPAmount baseFee);
188
189 static NotTEC
190 checkSign(PreclaimContext const& ctx);
191
192 static NotTEC
194
195 // Returns the fee in fee units, not scaled for load.
196 static XRPAmount
197 calculateBaseFee(ReadView const& view, STTx const& tx);
198
199 static TER
201 {
202 // Most transactors do nothing
203 // after checkSeq/Fee/Sign.
204 return tesSUCCESS;
205 }
206
207 static TER
208 checkPermission(ReadView const& view, STTx const& tx);
210
211 // Interface used by DeleteAccount
212 static TER
215 AccountID const& account,
216 uint256 const& ticketIndex,
218
219protected:
220 TER
221 apply();
222
223 explicit Transactor(ApplyContext& ctx);
224
225 virtual void
226 preCompute();
227
228 virtual TER
229 doApply() = 0;
230
240 static XRPAmount
242 Application& app,
243 XRPAmount baseFee,
244 Fees const& fees,
245 ApplyFlags flags);
246
247private:
249 reset(XRPAmount fee);
250
251 TER
252 consumeSeqProxy(SLE::pointer const& sleAccount);
253 TER
254 payFee();
255 static NotTEC
257 AccountID const& idSigner,
258 AccountID const& idAccount,
260 Rules const& rules,
262 static NotTEC
264 ReadView const& view,
265 AccountID const& idAccount,
266 STArray const& txSigners,
267 ApplyFlags const& flags,
269
270 void trapTransaction(uint256) const;
271};
272
274NotTEC
275preflight0(PreflightContext const& ctx);
276
278NotTEC
279preflight1(PreflightContext const& ctx);
280
282NotTEC
283preflight2(PreflightContext const& ctx);
284
285} // namespace ripple
286
287#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:78
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:144
A view into a ledger.
Definition: ReadView.h:52
Rules controlling protocol behavior.
Definition: Rules.h:38
TER consumeSeqProxy(SLE::pointer const &sleAccount)
Definition: Transactor.cpp:460
ApplyResult operator()()
Process the transaction.
Transactor & operator=(Transactor const &)=delete
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
Definition: Transactor.cpp:430
static TER checkFee(PreclaimContext const &ctx, XRPAmount baseFee)
Definition: Transactor.cpp:258
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:230
static NotTEC checkSeqProxy(ReadView const &view, STTx const &tx, beast::Journal j)
Definition: Transactor.cpp:358
static NotTEC checkSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:578
void trapTransaction(uint256) const
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:248
virtual ~Transactor()=default
static NotTEC checkSingleSign(AccountID const &idSigner, AccountID const &idAccount, std::shared_ptr< SLE const > sleAccount, Rules const &rules, beast::Journal j)
Definition: Transactor.cpp:682
AccountID const account_
Definition: Transactor.h:143
static NotTEC checkMultiSign(ReadView const &view, AccountID const &idAccount, STArray const &txSigners, ApplyFlags const &flags, beast::Journal j)
Definition: Transactor.cpp:743
static TER checkPermission(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:214
ApplyView & view()
Definition: Transactor.h:159
static TER preclaim(PreclaimContext const &ctx)
Definition: Transactor.h:200
static NotTEC checkBatchSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:635
beast::Journal const j_
Definition: Transactor.h:141
XRPAmount mPriorBalance
Definition: Transactor.h:144
virtual void preCompute()
Definition: Transactor.cpp:533
static TER ticketDelete(ApplyView &view, AccountID const &account, uint256 const &ticketIndex, beast::Journal j)
Definition: Transactor.cpp:479
XRPAmount mSourceBalance
Definition: Transactor.h:145
ApplyContext & ctx_
Definition: Transactor.h:140
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:999
Transactor(Transactor const &)=delete
ApplyView const & view() const
Definition: Transactor.h:165
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:25
NotTEC preflight0(PreflightContext const &ctx)
Performs early sanity checks on the txid.
Definition: Transactor.cpp:44
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:91
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:160
@ tesSUCCESS
Definition: TER.h:244
ApplyFlags
Definition: ApplyView.h:31
@ tapBATCH
Definition: ApplyView.h:46
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:79
ReadView const & view
Definition: Transactor.h:82
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:110
PreclaimContext(Application &app_, ReadView const &view_, TER preflightResult_, STTx const &tx_, ApplyFlags flags_, std::optional< uint256 > parentBatchId_, beast::Journal j_=beast::Journal{beast::Journal::getNullSink()})
Definition: Transactor.h:89
std::optional< uint256 const > const parentBatchId
Definition: Transactor.h:86
Application & app
Definition: Transactor.h:81
beast::Journal const j
Definition: Transactor.h:87
State information when preflighting a tx.
Definition: Transactor.h:34
PreflightContext(Application &app_, STTx const &tx_, uint256 parentBatchId_, Rules const &rules_, ApplyFlags flags_, beast::Journal j_=beast::Journal{beast::Journal::getNullSink()})
Definition: Transactor.h:43
std::optional< uint256 const > parentBatchId
Definition: Transactor.h:40
beast::Journal const j
Definition: Transactor.h:41
PreflightContext(Application &app_, STTx const &tx_, Rules const &rules_, ApplyFlags flags_, beast::Journal j_=beast::Journal{beast::Journal::getNullSink()})
Definition: Transactor.h:61
PreflightContext & operator=(PreflightContext const &)=delete
Describes the results of the preflight check.
Definition: applySteps.h:164