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;
41
43 Application& app_,
44 STTx const& tx_,
45 Rules const& rules_,
46 ApplyFlags flags_,
48
50 operator=(PreflightContext const&) = delete;
51};
52
55{
56public:
58 ReadView const& view;
60 STTx const& tx;
63
65 Application& app_,
66 ReadView const& view_,
67 TER preflightResult_,
68 STTx const& tx_,
69 ApplyFlags flags_,
71 : app(app_)
72 , view(view_)
73 , preflightResult(preflightResult_)
74 , tx(tx_)
75 , flags(flags_)
76 , j(j_)
77 {
78 }
79
80 PreclaimContext&
81 operator=(PreclaimContext const&) = delete;
82};
83
84class TxConsequences;
85struct PreflightResult;
86
88{
89protected:
92
94 XRPAmount mPriorBalance; // Balance before fees.
95 XRPAmount mSourceBalance; // Balance after fees.
96
97 virtual ~Transactor() = default;
98 Transactor(Transactor const&) = delete;
100 operator=(Transactor const&) = delete;
101
102public:
106 operator()();
107
108 ApplyView&
110 {
111 return ctx_.view();
112 }
113
114 ApplyView const&
115 view() const
116 {
117 return ctx_.view();
118 }
119
121 /*
122 These static functions are called from invoke_preclaim<Tx>
123 using name hiding to accomplish compile-time polymorphism,
124 so derived classes can override for different or extra
125 functionality. Use with care, as these are not really
126 virtual and so don't have the compiler-time protection that
127 comes with it.
128 */
129
130 static NotTEC
131 checkSeqProxy(ReadView const& view, STTx const& tx, beast::Journal j);
132
133 static NotTEC
135
136 static TER
137 checkFee(PreclaimContext const& ctx, XRPAmount baseFee);
138
139 static NotTEC
140 checkSign(PreclaimContext const& ctx);
141
142 // Returns the fee in fee units, not scaled for load.
143 static XRPAmount
144 calculateBaseFee(ReadView const& view, STTx const& tx);
145
146 static TER
148 {
149 // Most transactors do nothing
150 // after checkSeq/Fee/Sign.
151 return tesSUCCESS;
152 }
153
154 static TER
155 checkPermission(ReadView const& view, STTx const& tx);
157
158 // Interface used by DeleteAccount
159 static TER
162 AccountID const& account,
163 uint256 const& ticketIndex,
165
166protected:
167 TER
168 apply();
169
170 explicit Transactor(ApplyContext& ctx);
171
172 virtual void
173 preCompute();
174
175 virtual TER
176 doApply() = 0;
177
187 static XRPAmount
189 Application& app,
190 XRPAmount baseFee,
191 Fees const& fees,
192 ApplyFlags flags);
193
194private:
196 reset(XRPAmount fee);
197
198 TER
199 consumeSeqProxy(SLE::pointer const& sleAccount);
200 TER
201 payFee();
202 static NotTEC
204 static NotTEC
206
207 void trapTransaction(uint256) const;
208};
209
211NotTEC
212preflight0(PreflightContext const& ctx);
213
215NotTEC
216preflight1(PreflightContext const& ctx);
217
219NotTEC
220preflight2(PreflightContext const& ctx);
221
222} // namespace ripple
223
224#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:440
ApplyResult operator()()
Process the transaction.
Definition: Transactor.cpp:970
Transactor & operator=(Transactor const &)=delete
static NotTEC checkPriorTxAndLastLedger(PreclaimContext const &ctx)
Definition: Transactor.cpp:410
static TER checkFee(PreclaimContext const &ctx, XRPAmount baseFee)
Definition: Transactor.cpp:248
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:220
static NotTEC checkSeqProxy(ReadView const &view, STTx const &tx, beast::Journal j)
Definition: Transactor.cpp:338
static NotTEC checkSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:558
void trapTransaction(uint256) const
Definition: Transactor.cpp:963
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:238
virtual ~Transactor()=default
static NotTEC checkSingleSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:576
AccountID const account_
Definition: Transactor.h:93
static TER checkPermission(ReadView const &view, STTx const &tx)
Definition: Transactor.cpp:204
ApplyView & view()
Definition: Transactor.h:109
static TER preclaim(PreclaimContext const &ctx)
Definition: Transactor.h:147
beast::Journal const j_
Definition: Transactor.h:91
XRPAmount mPriorBalance
Definition: Transactor.h:94
virtual void preCompute()
Definition: Transactor.cpp:513
static TER ticketDelete(ApplyView &view, AccountID const &account, uint256 const &ticketIndex, beast::Journal j)
Definition: Transactor.cpp:459
XRPAmount mSourceBalance
Definition: Transactor.h:95
ApplyContext & ctx_
Definition: Transactor.h:90
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:909
Transactor(Transactor const &)=delete
ApplyView const & view() const
Definition: Transactor.h:115
static NotTEC checkMultiSign(PreclaimContext const &ctx)
Definition: Transactor.cpp:658
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:43
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:83
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:144
@ 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:55
ReadView const & view
Definition: Transactor.h:58
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:64
Application & app
Definition: Transactor.h:57
beast::Journal const j
Definition: Transactor.h:62
State information when preflighting a tx.
Definition: Transactor.h:34
beast::Journal const j
Definition: Transactor.h:40
PreflightContext & operator=(PreflightContext const &)=delete
Describes the results of the preflight check.
Definition: applySteps.h:164