11use crate :: { Receipt , ReceiptWithBloom , TxType } ;
2- use alloy_eips:: eip2718:: { Decodable2718 , Eip2718Error , Encodable2718 } ;
2+ use alloy_eips:: eip2718:: { Decodable2718 , Encodable2718 } ;
33use alloy_rlp:: { length_of_length, BufMut , Decodable , Encodable } ;
44
55/// Receipt envelope, as defined in [EIP-2718].
@@ -16,8 +16,6 @@ use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable};
1616pub enum ReceiptEnvelope {
1717 /// Receipt envelope with no type flag.
1818 Legacy ( ReceiptWithBloom ) ,
19- /// Receipt envelope with type flag 0.
20- TaggedLegacy ( ReceiptWithBloom ) ,
2119 /// Receipt envelope with type flag 1, containing a [EIP-2930] receipt.
2220 ///
2321 /// [EIP-2930]: https://eips.ethereum.org/EIPS/eip-2930
@@ -36,7 +34,7 @@ impl ReceiptEnvelope {
3634 /// Return the [`TxType`] of the inner receipt.
3735 pub const fn tx_type ( & self ) -> TxType {
3836 match self {
39- Self :: Legacy ( _) | Self :: TaggedLegacy ( _ ) => TxType :: Legacy ,
37+ Self :: Legacy ( _) => TxType :: Legacy ,
4038 Self :: Eip2930 ( _) => TxType :: Eip2930 ,
4139 Self :: Eip1559 ( _) => TxType :: Eip1559 ,
4240 Self :: Eip4844 ( _) => TxType :: Eip4844 ,
@@ -47,23 +45,17 @@ impl ReceiptEnvelope {
4745 /// however, future receipt types may be added.
4846 pub const fn as_receipt_with_bloom ( & self ) -> Option < & ReceiptWithBloom > {
4947 match self {
50- Self :: Legacy ( t)
51- | Self :: TaggedLegacy ( t)
52- | Self :: Eip2930 ( t)
53- | Self :: Eip1559 ( t)
54- | Self :: Eip4844 ( t) => Some ( t) ,
48+ Self :: Legacy ( t) | Self :: Eip2930 ( t) | Self :: Eip1559 ( t) | Self :: Eip4844 ( t) => Some ( t) ,
5549 }
5650 }
5751
5852 /// Return the inner receipt. Currently this is infallible, however, future
5953 /// receipt types may be added.
6054 pub const fn as_receipt ( & self ) -> Option < & Receipt > {
6155 match self {
62- Self :: Legacy ( t)
63- | Self :: TaggedLegacy ( t)
64- | Self :: Eip2930 ( t)
65- | Self :: Eip1559 ( t)
66- | Self :: Eip4844 ( t) => Some ( & t. receipt ) ,
56+ Self :: Legacy ( t) | Self :: Eip2930 ( t) | Self :: Eip1559 ( t) | Self :: Eip4844 ( t) => {
57+ Some ( & t. receipt )
58+ }
6759 }
6860 }
6961
@@ -100,7 +92,6 @@ impl Decodable for ReceiptEnvelope {
10092 fn decode ( buf : & mut & [ u8 ] ) -> alloy_rlp:: Result < Self > {
10193 match Self :: network_decode ( buf) {
10294 Ok ( t) => Ok ( t) ,
103- Err ( Eip2718Error :: RlpError ( e) ) => Err ( e) ,
10495 Err ( _) => Err ( alloy_rlp:: Error :: Custom ( "Unexpected type" ) ) ,
10596 }
10697 }
@@ -110,7 +101,6 @@ impl Encodable2718 for ReceiptEnvelope {
110101 fn type_flag ( & self ) -> Option < u8 > {
111102 match self {
112103 Self :: Legacy ( _) => None ,
113- Self :: TaggedLegacy ( _) => Some ( TxType :: Legacy as u8 ) ,
114104 Self :: Eip2930 ( _) => Some ( TxType :: Eip2930 as u8 ) ,
115105 Self :: Eip1559 ( _) => Some ( TxType :: Eip1559 as u8 ) ,
116106 Self :: Eip4844 ( _) => Some ( TxType :: Eip4844 as u8 ) ,
@@ -131,30 +121,31 @@ impl Encodable2718 for ReceiptEnvelope {
131121}
132122
133123impl Decodable2718 for ReceiptEnvelope {
134- fn typed_decode ( ty : u8 , buf : & mut & [ u8 ] ) -> Result < Self , Eip2718Error > {
124+ fn typed_decode ( ty : u8 , buf : & mut & [ u8 ] ) -> alloy_rlp :: Result < Self > {
135125 let receipt = Decodable :: decode ( buf) ?;
136- match ty. try_into ( ) ? {
137- TxType :: Legacy => Ok ( Self :: TaggedLegacy ( receipt) ) ,
126+ match ty. try_into ( ) . map_err ( |_| alloy_rlp:: Error :: Custom ( "Unexpected type" ) ) ? {
138127 TxType :: Eip2930 => Ok ( Self :: Eip2930 ( receipt) ) ,
139128 TxType :: Eip1559 => Ok ( Self :: Eip1559 ( receipt) ) ,
140129 TxType :: Eip4844 => Ok ( Self :: Eip4844 ( receipt) ) ,
130+ TxType :: Legacy => {
131+ Err ( alloy_rlp:: Error :: Custom ( "type-0 eip2718 transactions are not supported" ) )
132+ }
141133 }
142134 }
143135
144- fn fallback_decode ( buf : & mut & [ u8 ] ) -> Result < Self , Eip2718Error > {
136+ fn fallback_decode ( buf : & mut & [ u8 ] ) -> alloy_rlp :: Result < Self > {
145137 Ok ( Self :: Legacy ( Decodable :: decode ( buf) ?) )
146138 }
147139}
148140
149141#[ cfg( any( test, feature = "arbitrary" ) ) ]
150142impl < ' a > arbitrary:: Arbitrary < ' a > for ReceiptEnvelope {
151143 fn arbitrary ( u : & mut arbitrary:: Unstructured < ' a > ) -> arbitrary:: Result < Self > {
152- let tx_type = u. int_in_range ( - 1 ..=2 ) ?;
144+ let tx_type = u. int_in_range ( 0 ..=2 ) ?;
153145 let receipt = Receipt :: arbitrary ( u) ?. with_bloom ( ) ;
154146
155147 match tx_type {
156- -1 => Ok ( Self :: Legacy ( receipt) ) ,
157- 0 => Ok ( Self :: TaggedLegacy ( receipt) ) ,
148+ 0 => Ok ( Self :: Legacy ( receipt) ) ,
158149 1 => Ok ( Self :: Eip2930 ( receipt) ) ,
159150 2 => Ok ( Self :: Eip1559 ( receipt) ) ,
160151 _ => unreachable ! ( ) ,
0 commit comments