@@ -139,9 +139,15 @@ impl TryFrom<TransactionReceipt> for alloy_rpc_types::TransactionReceipt {
139139 alloy_consensus:: TxType :: try_from ( receipt. tx_type ) ?,
140140 alloy_consensus:: ReceiptWithBloom {
141141 receipt : alloy_consensus:: Receipt {
142- status : validate_receipt_status ( & receipt. block_number , receipt. status ) ?,
143- // TODO XC-412: This field is required, why is it missing from `evm_rpc_types::TransactionReceipt`?
144- cumulative_gas_used : 0 ,
142+ status : validate_receipt_status (
143+ & receipt. block_number ,
144+ receipt. root ,
145+ receipt. status ,
146+ ) ?,
147+ cumulative_gas_used : try_from_nat256 (
148+ receipt. cumulative_gas_used ,
149+ "cumulative_gas_used" ,
150+ ) ?,
145151 logs : receipt
146152 . logs
147153 . into_iter ( )
@@ -176,13 +182,11 @@ impl TryFrom<HexByte> for alloy_consensus::TxType {
176182 type Error = RpcError ;
177183
178184 fn try_from ( value : HexByte ) -> Result < Self , Self :: Error > {
179- Ok (
180- alloy_consensus:: TxType :: try_from ( value. into_byte ( ) ) . map_err ( |e| {
181- RpcError :: ValidationError ( ValidationError :: Custom ( format ! (
182- "Unable to parse transaction type: {e:?}"
183- ) ) )
184- } ) ?,
185- )
185+ alloy_consensus:: TxType :: try_from ( value. into_byte ( ) ) . map_err ( |e| {
186+ RpcError :: ValidationError ( ValidationError :: Custom ( format ! (
187+ "Unable to parse transaction type: {e:?}"
188+ ) ) )
189+ } )
186190 }
187191}
188192
@@ -192,32 +196,35 @@ fn validate_difficulty(number: &Nat256, difficulty: Option<Nat256>) -> Result<U2
192196 difficulty
193197 . map ( U256 :: from)
194198 . ok_or ( RpcError :: ValidationError ( ValidationError :: Custom (
195- "Missing difficulty in pre- Paris block" . into ( ) ,
199+ "Missing difficulty field in pre Paris upgrade block" . into ( ) ,
196200 ) ) )
197201 } else {
198202 match difficulty. map ( U256 :: from) {
199203 None | Some ( U256 :: ZERO ) => Ok ( U256 :: ZERO ) ,
200204 _ => Err ( RpcError :: ValidationError ( ValidationError :: Custom (
201- "Post- Paris block has non-zero difficulty" . into ( ) ,
205+ "Post Paris upgrade block has non-zero difficulty" . into ( ) ,
202206 ) ) ) ,
203207 }
204208 }
205209}
206210
207211fn validate_receipt_status (
208212 number : & Nat256 ,
213+ root : Option < Hex32 > ,
209214 status : Option < Nat256 > ,
210215) -> Result < alloy_consensus:: Eip658Value , RpcError > {
211216 const BYZANTIUM_BLOCK : u64 = 4_370_000 ;
212217 if number. as_ref ( ) < & Nat :: from ( BYZANTIUM_BLOCK ) {
213- // TODO XC-412: How do we want to handle pre-Byzantium blocks?
214- Err ( RpcError :: ValidationError ( ValidationError :: Custom (
215- "Missing state root in pre-Byzantium receipt" . into ( ) ,
216- ) ) )
218+ match root {
219+ None => Err ( RpcError :: ValidationError ( ValidationError :: Custom (
220+ "Missing root field in transaction included before the Byzantium upgrade" . into ( ) ,
221+ ) ) ) ,
222+ Some ( root) => Ok ( alloy_consensus:: Eip658Value :: PostState ( B256 :: from ( root) ) ) ,
223+ }
217224 } else {
218225 match status. map ( U256 :: from) {
219226 None => Err ( RpcError :: ValidationError ( ValidationError :: Custom (
220- "Missing status in post- Byzantium receipt " . into ( ) ,
227+ "Missing status field in transaction included after the Byzantium upgrade " . into ( ) ,
221228 ) ) ) ,
222229 Some ( U256 :: ZERO ) => Ok ( alloy_consensus:: Eip658Value :: Eip658 ( false ) ) ,
223230 Some ( U256 :: ONE ) => Ok ( alloy_consensus:: Eip658Value :: Eip658 ( true ) ) ,
0 commit comments