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