1
1
use crate :: {
2
- serde_bincode_compat:: SerdeBincodeCompat ,
3
2
size:: InMemorySize ,
4
3
transaction:: signed:: { RecoveryError , SignedTransaction } ,
5
4
} ;
@@ -10,10 +9,9 @@ use alloy_eips::{
10
9
eip7702:: SignedAuthorization ,
11
10
Decodable2718 , Encodable2718 , Typed2718 ,
12
11
} ;
13
- use alloy_primitives:: { bytes :: Buf , ChainId , Signature , TxHash } ;
12
+ use alloy_primitives:: { ChainId , Signature , TxHash } ;
14
13
use alloy_rlp:: { BufMut , Decodable , Encodable , Result as RlpResult } ;
15
14
use op_alloy_consensus:: { OpPooledTransaction , OpTxEnvelope } ;
16
- use reth_codecs:: Compact ;
17
15
use revm_primitives:: { Address , Bytes , TxKind , B256 , U256 } ;
18
16
19
17
macro_rules! delegate {
@@ -32,7 +30,8 @@ macro_rules! delegate {
32
30
///
33
31
/// Note: The other transaction type variants must not overlap with the builtin one, transaction
34
32
/// types must be unique.
35
- #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize , Hash , Eq , PartialEq ) ]
33
+ #[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
34
+ #[ derive( Debug , Clone , Hash , Eq , PartialEq ) ]
36
35
pub enum ExtendedTxEnvelope < BuiltIn , Other > {
37
36
/// The builtin transaction type.
38
37
BuiltIn ( BuiltIn ) ,
@@ -298,59 +297,73 @@ where
298
297
}
299
298
}
300
299
301
- #[ derive( Debug , serde:: Serialize , serde:: Deserialize ) ]
302
- pub enum ExtendedTxEnvelopeRepr < ' a , B : SerdeBincodeCompat , T : SerdeBincodeCompat > {
303
- BuiltIn ( B :: BincodeRepr < ' a > ) ,
304
- Other ( T :: BincodeRepr < ' a > ) ,
305
- }
300
+ #[ cfg( feature = "serde-bincode-compat" ) ]
301
+ mod serde_bincode_compat {
302
+ use super :: * ;
303
+ use crate :: serde_bincode_compat:: SerdeBincodeCompat ;
306
304
307
- impl < B , T > SerdeBincodeCompat for ExtendedTxEnvelope < B , T >
308
- where
309
- B : SerdeBincodeCompat + std :: fmt :: Debug ,
310
- T : SerdeBincodeCompat + std :: fmt :: Debug ,
311
- {
312
- type BincodeRepr < ' a > = ExtendedTxEnvelopeRepr < ' a , B , T > ;
305
+ # [ cfg_attr ( feature = "serde" , derive ( serde :: Serialize , serde :: Deserialize ) ) ]
306
+ # [ derive ( Debug ) ]
307
+ pub enum ExtendedTxEnvelopeRepr < ' a , B : SerdeBincodeCompat , T : SerdeBincodeCompat > {
308
+ BuiltIn ( B :: BincodeRepr < ' a > ) ,
309
+ Other ( T :: BincodeRepr < ' a > ) ,
310
+ }
313
311
314
- fn as_repr ( & self ) -> Self :: BincodeRepr < ' _ > {
315
- match self {
316
- Self :: BuiltIn ( tx) => ExtendedTxEnvelopeRepr :: BuiltIn ( tx. as_repr ( ) ) ,
317
- Self :: Other ( tx) => ExtendedTxEnvelopeRepr :: Other ( tx. as_repr ( ) ) ,
312
+ impl < B , T > SerdeBincodeCompat for ExtendedTxEnvelope < B , T >
313
+ where
314
+ B : SerdeBincodeCompat + std:: fmt:: Debug ,
315
+ T : SerdeBincodeCompat + std:: fmt:: Debug ,
316
+ {
317
+ type BincodeRepr < ' a > = ExtendedTxEnvelopeRepr < ' a , B , T > ;
318
+
319
+ fn as_repr ( & self ) -> Self :: BincodeRepr < ' _ > {
320
+ match self {
321
+ Self :: BuiltIn ( tx) => ExtendedTxEnvelopeRepr :: BuiltIn ( tx. as_repr ( ) ) ,
322
+ Self :: Other ( tx) => ExtendedTxEnvelopeRepr :: Other ( tx. as_repr ( ) ) ,
323
+ }
318
324
}
319
- }
320
325
321
- fn from_repr ( repr : Self :: BincodeRepr < ' _ > ) -> Self {
322
- match repr {
323
- ExtendedTxEnvelopeRepr :: BuiltIn ( tx_repr) => Self :: BuiltIn ( B :: from_repr ( tx_repr) ) ,
324
- ExtendedTxEnvelopeRepr :: Other ( tx_repr) => Self :: Other ( T :: from_repr ( tx_repr) ) ,
326
+ fn from_repr ( repr : Self :: BincodeRepr < ' _ > ) -> Self {
327
+ match repr {
328
+ ExtendedTxEnvelopeRepr :: BuiltIn ( tx_repr) => Self :: BuiltIn ( B :: from_repr ( tx_repr) ) ,
329
+ ExtendedTxEnvelopeRepr :: Other ( tx_repr) => Self :: Other ( T :: from_repr ( tx_repr) ) ,
330
+ }
325
331
}
326
332
}
327
333
}
328
334
329
- impl < B , T > Compact for ExtendedTxEnvelope < B , T >
330
- where
331
- B : Transaction + IsTyped2718 + Compact ,
332
- T : Transaction + Compact ,
333
- {
334
- fn to_compact < Buf > ( & self , buf : & mut Buf ) -> usize
335
+ #[ cfg( feature = "reth-codec" ) ]
336
+ mod compact {
337
+ use super :: * ;
338
+ use alloy_rlp:: Buf ;
339
+ use reth_codecs:: Compact ;
340
+
341
+ impl < B , T > Compact for ExtendedTxEnvelope < B , T >
335
342
where
336
- Buf : alloy_rlp:: bytes:: BufMut + AsMut < [ u8 ] > ,
343
+ B : Transaction + IsTyped2718 + Compact ,
344
+ T : Transaction + Compact ,
337
345
{
338
- buf. put_u8 ( self . ty ( ) ) ;
339
- match self {
340
- Self :: BuiltIn ( tx) => tx. to_compact ( buf) ,
341
- Self :: Other ( tx) => tx. to_compact ( buf) ,
346
+ fn to_compact < Buf > ( & self , buf : & mut Buf ) -> usize
347
+ where
348
+ Buf : alloy_rlp:: bytes:: BufMut + AsMut < [ u8 ] > ,
349
+ {
350
+ buf. put_u8 ( self . ty ( ) ) ;
351
+ match self {
352
+ Self :: BuiltIn ( tx) => tx. to_compact ( buf) ,
353
+ Self :: Other ( tx) => tx. to_compact ( buf) ,
354
+ }
342
355
}
343
- }
344
356
345
- fn from_compact ( mut buf : & [ u8 ] , len : usize ) -> ( Self , & [ u8 ] ) {
346
- let type_byte = buf. get_u8 ( ) ;
357
+ fn from_compact ( mut buf : & [ u8 ] , len : usize ) -> ( Self , & [ u8 ] ) {
358
+ let type_byte = buf. get_u8 ( ) ;
347
359
348
- if <B as IsTyped2718 >:: is_type ( type_byte) {
349
- let ( tx, remaining) = B :: from_compact ( buf, len) ;
350
- return ( Self :: BuiltIn ( tx) , remaining) ;
351
- }
360
+ if <B as IsTyped2718 >:: is_type ( type_byte) {
361
+ let ( tx, remaining) = B :: from_compact ( buf, len) ;
362
+ return ( Self :: BuiltIn ( tx) , remaining) ;
363
+ }
352
364
353
- let ( tx, remaining) = T :: from_compact ( buf, len) ;
354
- ( Self :: Other ( tx) , remaining)
365
+ let ( tx, remaining) = T :: from_compact ( buf, len) ;
366
+ ( Self :: Other ( tx) , remaining)
367
+ }
355
368
}
356
369
}
0 commit comments