@@ -17,7 +17,7 @@ use std::str::FromStr;
17
17
pub use revm_primitives:: { alloy_primitives:: TxKind , Transaction , TransactionValidation } ;
18
18
use revm_primitives:: { ruint, B256 } ;
19
19
20
- use crate :: { AccessListItem , Address , Bytes , U256 , U8 } ;
20
+ use crate :: { signature :: Signature , Bytes , U256 , U8 } ;
21
21
22
22
pub const INVALID_TX_TYPE_ERROR_MESSAGE : & str = "invalid tx type" ;
23
23
@@ -72,6 +72,18 @@ impl From<Type> for u8 {
72
72
}
73
73
}
74
74
75
+ impl IsEip4844 for Type {
76
+ fn is_eip4844 ( & self ) -> bool {
77
+ matches ! ( self , Type :: Eip4844 )
78
+ }
79
+ }
80
+
81
+ impl IsLegacy for Type {
82
+ fn is_legacy ( & self ) -> bool {
83
+ matches ! ( self , Type :: Legacy )
84
+ }
85
+ }
86
+
75
87
#[ derive( Debug , thiserror:: Error ) ]
76
88
pub enum ParseError {
77
89
#[ error( "{0}" ) ]
@@ -148,14 +160,15 @@ impl serde::Serialize for Type {
148
160
}
149
161
}
150
162
151
- pub trait SignedTransaction : Transaction + TransactionType {
163
+ /// Trait for information about executable transactions.
164
+ pub trait ExecutableTransaction {
152
165
/// The effective gas price of the transaction, calculated using the
153
166
/// provided block base fee. Only applicable for post-EIP-1559 transactions.
154
167
fn effective_gas_price ( & self , block_base_fee : U256 ) -> Option < U256 > ;
155
168
156
169
/// The maximum fee per gas the sender is willing to pay. Only applicable
157
170
/// for post-EIP-1559 transactions.
158
- fn max_fee_per_gas ( & self ) -> Option < U256 > ;
171
+ fn max_fee_per_gas ( & self ) -> Option < & U256 > ;
159
172
160
173
/// The enveloped (EIP-2718) RLP-encoding of the transaction.
161
174
fn rlp_encoding ( & self ) -> & Bytes ;
@@ -168,71 +181,67 @@ pub trait SignedTransaction: Transaction + TransactionType {
168
181
fn transaction_hash ( & self ) -> & B256 ;
169
182
}
170
183
184
+ /// Trait for transactions that may be signed.
185
+ pub trait MaybeSignedTransaction {
186
+ /// Returns the [`Signature`] of the transaction, if any.
187
+ fn maybe_signature ( & self ) -> Option < & dyn Signature > ;
188
+ }
189
+
190
+ /// Trait for transactions that have been signed.
191
+ pub trait SignedTransaction {
192
+ /// Returns the [`Signature`] of the transaction.
193
+ fn signature ( & self ) -> & dyn Signature ;
194
+ }
195
+
196
+ impl < TransactionT : SignedTransaction > MaybeSignedTransaction for TransactionT {
197
+ fn maybe_signature ( & self ) -> Option < & dyn Signature > {
198
+ Some ( self . signature ( ) )
199
+ }
200
+ }
201
+
202
+ /// Trait for mutable transactions.
171
203
pub trait TransactionMut {
172
204
/// Sets the gas limit of the transaction.
173
205
fn set_gas_limit ( & mut self , gas_limit : u64 ) ;
174
206
}
175
207
208
+ /// Trait for determining the type of a transaction.
176
209
pub trait TransactionType {
177
210
/// Type of the transaction.
178
- type Type ;
211
+ type Type : Into < u8 > ;
179
212
180
213
/// Returns the type of the transaction.
181
214
fn transaction_type ( & self ) -> Self :: Type ;
182
215
}
183
216
184
- pub fn max_cost ( transaction : & impl SignedTransaction ) -> U256 {
185
- U256 :: from ( transaction. gas_limit ( ) ) . saturating_mul ( * transaction. gas_price ( ) )
217
+ /// Trait for determining whether a transaction has an access list.
218
+ pub trait HasAccessList {
219
+ /// Whether the transaction has an access list.
220
+ fn has_access_list ( & self ) -> bool ;
186
221
}
187
222
188
- pub fn upfront_cost ( transaction : & impl SignedTransaction ) -> U256 {
189
- max_cost ( transaction) . saturating_add ( * transaction. value ( ) )
223
+ /// Trait for determining whether a transaction is an EIP-155 transaction.
224
+ pub trait IsEip155 {
225
+ /// Whether the transaction is an EIP-155 transaction.
226
+ fn is_eip155 ( & self ) -> bool ;
190
227
}
191
228
192
- /// Represents _all_ transaction requests received from RPC
193
- #[ derive( Clone , Debug , PartialEq , Eq , Default ) ]
194
- #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
195
- #[ cfg_attr( feature = "serde" , serde( rename_all = "camelCase" ) ) ]
196
- pub struct EthTransactionRequest {
197
- /// from address
198
- pub from : Address ,
199
- /// to address
200
- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
201
- pub to : Option < Address > ,
202
- /// legacy, gas Price
203
- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
204
- pub gas_price : Option < U256 > ,
205
- /// max base fee per gas sender is willing to pay
206
- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
207
- pub max_fee_per_gas : Option < U256 > ,
208
- /// miner tip
209
- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
210
- pub max_priority_fee_per_gas : Option < U256 > ,
211
- /// gas
212
- #[ cfg_attr( feature = "serde" , serde( default , with = "crate::serde::optional_u64" ) ) ]
213
- pub gas : Option < u64 > ,
214
- /// value of th tx in wei
215
- pub value : Option < U256 > ,
216
- /// Any additional data sent
217
- #[ cfg_attr( feature = "serde" , serde( alias = "input" ) ) ]
218
- pub data : Option < Bytes > ,
219
- /// Transaction nonce
220
- #[ cfg_attr( feature = "serde" , serde( default , with = "crate::serde::optional_u64" ) ) ]
221
- pub nonce : Option < u64 > ,
222
- /// Chain ID
223
- #[ cfg_attr( feature = "serde" , serde( default , with = "crate::serde::optional_u64" ) ) ]
224
- pub chain_id : Option < u64 > ,
225
- /// warm storage access pre-payment
226
- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
227
- pub access_list : Option < Vec < AccessListItem > > ,
228
- /// EIP-2718 type
229
- #[ cfg_attr(
230
- feature = "serde" ,
231
- serde( default , rename = "type" , with = "crate::serde::optional_u8" )
232
- ) ]
233
- pub transaction_type : Option < u8 > ,
234
- /// Blobs (EIP-4844)
235
- pub blobs : Option < Vec < Bytes > > ,
236
- /// Blob versioned hashes (EIP-4844)
237
- pub blob_hashes : Option < Vec < B256 > > ,
229
+ /// Trait for determining whether a transaction is an EIP-4844 transaction.
230
+ pub trait IsEip4844 {
231
+ /// Whether the transaction is an EIP-4844 transaction.
232
+ fn is_eip4844 ( & self ) -> bool ;
233
+ }
234
+
235
+ /// Trait for determining whether a transaction is a legacy transaction.
236
+ pub trait IsLegacy {
237
+ /// Whether the transaction is a legacy transaction.
238
+ fn is_legacy ( & self ) -> bool ;
239
+ }
240
+
241
+ pub fn max_cost ( transaction : & impl Transaction ) -> U256 {
242
+ U256 :: from ( transaction. gas_limit ( ) ) . saturating_mul ( * transaction. gas_price ( ) )
243
+ }
244
+
245
+ pub fn upfront_cost ( transaction : & impl Transaction ) -> U256 {
246
+ max_cost ( transaction) . saturating_add ( * transaction. value ( ) )
238
247
}
0 commit comments