1
1
use crate :: Signed ;
2
2
use alloc:: vec:: Vec ;
3
- use alloy_eips:: eip2718:: { Eip2718Error , Eip2718Result } ;
3
+ use alloy_eips:: {
4
+ eip2718:: { Eip2718Error , Eip2718Result } ,
5
+ Typed2718 ,
6
+ } ;
4
7
use alloy_primitives:: { keccak256, PrimitiveSignature as Signature , TxHash } ;
5
8
use alloy_rlp:: { Buf , BufMut , Decodable , Encodable , Header } ;
6
9
7
10
/// Helper trait for managing RLP encoding of transactions inside 2718
8
11
#[ doc( hidden) ]
9
12
#[ doc( alias = "RlpEncodableTx" , alias = "RlpTxEncoding" ) ]
10
13
#[ auto_impl:: auto_impl( & , Arc ) ]
11
- pub trait RlpEcdsaEncodableTx : Sized {
12
- /// The default transaction type for this transaction.
13
- const DEFAULT_TX_TYPE : u8 ;
14
-
14
+ pub trait RlpEcdsaEncodableTx : Sized + Typed2718 {
15
15
/// Calculate the encoded length of the transaction's fields, without a RLP
16
16
/// header.
17
17
fn rlp_encoded_fields_length ( & self ) -> usize ;
@@ -71,7 +71,7 @@ pub trait RlpEcdsaEncodableTx: Sized {
71
71
/// EIP-2718 encode the transaction with the given signature and the default
72
72
/// type flag.
73
73
fn eip2718_encode ( & self , signature : & Signature , out : & mut dyn BufMut ) {
74
- self . eip2718_encode_with_type ( signature, Self :: DEFAULT_TX_TYPE , out) ;
74
+ self . eip2718_encode_with_type ( signature, self . ty ( ) , out) ;
75
75
}
76
76
77
77
/// Create an rlp header for the network encoded transaction. This will
@@ -97,7 +97,7 @@ pub trait RlpEcdsaEncodableTx: Sized {
97
97
/// Network encode the transaction with the given signature and the default
98
98
/// type flag.
99
99
fn network_encode ( & self , signature : & Signature , out : & mut dyn BufMut ) {
100
- self . network_encode_with_type ( signature, Self :: DEFAULT_TX_TYPE , out) ;
100
+ self . network_encode_with_type ( signature, self . ty ( ) , out) ;
101
101
}
102
102
103
103
/// Calculate the transaction hash for the given signature and type.
@@ -109,14 +109,17 @@ pub trait RlpEcdsaEncodableTx: Sized {
109
109
110
110
/// Calculate the transaction hash for the given signature.
111
111
fn tx_hash ( & self , signature : & Signature ) -> TxHash {
112
- self . tx_hash_with_type ( signature, Self :: DEFAULT_TX_TYPE )
112
+ self . tx_hash_with_type ( signature, self . ty ( ) )
113
113
}
114
114
}
115
115
116
116
/// Helper trait for managing RLP decoding of transactions inside 2718 envelopes.
117
117
#[ doc( hidden) ]
118
118
#[ doc( alias = "RlpDecodableTx" , alias = "RlpTxDecoding" ) ]
119
119
pub trait RlpEcdsaDecodableTx : RlpEcdsaEncodableTx {
120
+ /// The default transaction type for this transaction.
121
+ const DEFAULT_TX_TYPE : u8 ;
122
+
120
123
/// Decodes the fields of the transaction from RLP bytes. Do not decode a
121
124
/// header. You may assume the buffer is long enough to contain the
122
125
/// transaction.
0 commit comments