1
1
use core:: fmt;
2
2
3
+ use alloy:: primitives:: { Address , BlockNumber , BlockTimestamp , Bytes , TxIndex , B256 , U256 } ;
4
+ use alloy:: rpc:: types:: { Block as ExecutionBlock , Transaction as ExecutionTransaction } ;
3
5
use anyhow:: { Context , Result } ;
4
- use ethers:: types:: {
5
- Address , Block as EthersBlock , Bytes , Transaction as EthersTransaction , H256 , U256 , U64 ,
6
- } ;
6
+
7
7
use serde:: { Deserialize , Serialize } ;
8
8
9
9
use crate :: { clients:: beacon:: types:: Blob as BeaconBlob , utils:: web3:: calculate_versioned_hash} ;
10
10
11
11
#[ derive( Serialize , Deserialize , Debug ) ]
12
12
#[ serde( rename_all = "camelCase" ) ]
13
13
pub struct Block {
14
- pub number : U64 ,
15
- pub hash : H256 ,
16
- pub timestamp : U256 ,
14
+ pub number : BlockNumber ,
15
+ pub hash : B256 ,
16
+ pub timestamp : BlockTimestamp ,
17
17
pub slot : u32 ,
18
18
pub blob_gas_used : U256 ,
19
19
pub excess_blob_gas : U256 ,
@@ -22,24 +22,24 @@ pub struct Block {
22
22
#[ derive( Serialize , Deserialize , Debug ) ]
23
23
#[ serde( rename_all = "camelCase" ) ]
24
24
pub struct Transaction {
25
- pub hash : H256 ,
25
+ pub hash : B256 ,
26
26
pub from : Address ,
27
27
#[ serde( default , skip_serializing_if = "Option::is_none" ) ]
28
28
pub to : Option < Address > ,
29
- pub block_number : U64 ,
30
- pub index : U64 ,
29
+ pub block_number : BlockNumber ,
30
+ pub index : TxIndex ,
31
31
pub gas_price : U256 ,
32
32
pub max_fee_per_blob_gas : U256 ,
33
33
}
34
34
35
35
#[ derive( Serialize , Deserialize ) ]
36
36
#[ serde( rename_all = "camelCase" ) ]
37
37
pub struct Blob {
38
- pub versioned_hash : H256 ,
38
+ pub versioned_hash : B256 ,
39
39
pub commitment : String ,
40
40
pub proof : String ,
41
41
pub data : Bytes ,
42
- pub tx_hash : H256 ,
42
+ pub tx_hash : B256 ,
43
43
pub index : u32 ,
44
44
}
45
45
@@ -118,106 +118,106 @@ impl From<(u32, u32)> for FailedSlotsChunk {
118
118
}
119
119
}
120
120
121
- impl < ' a > TryFrom < ( & ' a EthersBlock < EthersTransaction > , u32 ) > for Block {
121
+ impl < ' a > TryFrom < ( & ' a ExecutionBlock < ExecutionTransaction > , u32 ) > for Block {
122
122
type Error = anyhow:: Error ;
123
123
124
124
fn try_from (
125
- ( ethers_block , slot) : ( & ' a EthersBlock < EthersTransaction > , u32 ) ,
125
+ ( execution_block , slot) : ( & ' a ExecutionBlock < ExecutionTransaction > , u32 ) ,
126
126
) -> Result < Self , Self :: Error > {
127
- let number = ethers_block
128
- . number
129
- . with_context ( || "Missing block number field in execution block" . to_string ( ) ) ?;
127
+ let number = execution_block. header . number ;
128
+ let hash = execution_block. header . hash ;
129
+ let timestamp = execution_block. header . timestamp ;
130
+ let blob_gas_used = match execution_block. header . blob_gas_used {
131
+ Some ( blob_gas_used) => U256 :: from :: < u64 > ( blob_gas_used) ,
132
+ None => {
133
+ return Err ( anyhow:: anyhow!(
134
+ "Missing `blob_gas_used` field in execution block {hash} with number {number}" ,
135
+ hash = hash,
136
+ number = number
137
+ ) )
138
+ }
139
+ } ;
140
+ let excess_blob_gas = match execution_block. header . excess_blob_gas {
141
+ Some ( excess_blob_gas) => U256 :: from :: < u64 > ( excess_blob_gas) ,
142
+ None => {
143
+ return Err ( anyhow:: anyhow!(
144
+ "Missing `excess_blob_gas` field in execution block {hash} with number {number}" ,
145
+ hash = hash,
146
+ number = number
147
+ ) )
148
+ }
149
+ } ;
130
150
131
151
Ok ( Self {
132
152
number,
133
- hash : ethers_block
134
- . hash
135
- . with_context ( || format ! ( "Missing block hash field in execution block {number}" ) ) ?,
136
- timestamp : ethers_block. timestamp ,
153
+ hash,
154
+ timestamp,
137
155
slot,
138
- blob_gas_used : match ethers_block. other . get ( "blobGasUsed" ) {
139
- Some ( blob_gas_used) => {
140
- let blob_gas_used = blob_gas_used. as_str ( ) . with_context ( || {
141
- format ! ( "Failed to convert `blobGasUsed` field in execution block {number}" )
142
- } ) ?;
143
-
144
- U256 :: from_str_radix ( blob_gas_used, 16 ) ?
145
- }
146
- None => {
147
- return Err ( anyhow:: anyhow!(
148
- "Missing `blobGasUsed` field in execution block {number}"
149
- ) )
150
- }
151
- } ,
152
- excess_blob_gas : match ethers_block. other . get ( "excessBlobGas" ) {
153
- Some ( excess_gas_gas) => {
154
- let excess_blob_gas = excess_gas_gas. as_str ( ) . with_context ( || {
155
- format ! (
156
- "Failed to convert excess blob gas field in execution block {number}"
157
- )
158
- } ) ?;
159
-
160
- U256 :: from_str_radix ( excess_blob_gas, 16 ) ?
161
- }
162
- None => {
163
- return Err ( anyhow:: anyhow!(
164
- "Missing `excessBlobGas` field in execution block {number}"
165
- ) )
166
- }
167
- } ,
156
+ blob_gas_used,
157
+ excess_blob_gas,
168
158
} )
169
159
}
170
160
}
171
161
172
- impl < ' a > TryFrom < ( & ' a EthersTransaction , & ' a EthersBlock < EthersTransaction > ) > for Transaction {
162
+ impl < ' a >
163
+ TryFrom < (
164
+ & ' a ExecutionTransaction ,
165
+ & ' a ExecutionBlock < ExecutionTransaction > ,
166
+ ) > for Transaction
167
+ {
173
168
type Error = anyhow:: Error ;
174
169
175
170
fn try_from (
176
- ( ethers_tx, ethers_block) : ( & ' a EthersTransaction , & ' a EthersBlock < EthersTransaction > ) ,
171
+ ( execution_tx, execution_block) : (
172
+ & ' a ExecutionTransaction ,
173
+ & ' a ExecutionBlock < ExecutionTransaction > ,
174
+ ) ,
177
175
) -> Result < Self , Self :: Error > {
178
- let hash = ethers_tx. hash ;
176
+ let hash = execution_tx. hash ;
177
+ let block_number = execution_block. header . number ;
178
+ let index = execution_tx
179
+ . transaction_index
180
+ . with_context ( || format ! ( "Missing `transaction_index` field in tx {hash}" ) ) ?;
181
+ let from = execution_tx. from ;
182
+ let to = execution_tx. to ;
183
+ let gas_price = match execution_tx. gas_price {
184
+ Some ( gas_price) => U256 :: from :: < u128 > ( gas_price) ,
185
+ None => {
186
+ return Err ( anyhow:: anyhow!(
187
+ "Missing `gas_price` field in tx {hash} in block {block_number}" ,
188
+ hash = hash,
189
+ block_number = block_number
190
+ ) )
191
+ }
192
+ } ;
193
+ let max_fee_per_blob_gas = match execution_tx. max_fee_per_blob_gas {
194
+ Some ( max_fee_per_blob_gas) => U256 :: from :: < u128 > ( max_fee_per_blob_gas) ,
195
+ None => {
196
+ return Err ( anyhow:: anyhow!(
197
+ "Missing `max_fee_per_blob_gas` field in tx {hash} in block {block_number}" ,
198
+ hash = hash,
199
+ block_number = block_number
200
+ ) )
201
+ }
202
+ } ;
179
203
180
204
Ok ( Self {
181
- block_number : ethers_block
182
- . number
183
- . with_context ( || "Missing block number field in execution block" . to_string ( ) ) ?,
184
- index : ethers_tx
185
- . transaction_index
186
- . with_context ( || "Missing transaction index field" . to_string ( ) ) ?,
205
+ block_number,
206
+ index,
187
207
hash,
188
- from : ethers_tx. from ,
189
- to : ethers_tx. to ,
190
- gas_price : ethers_tx. gas_price . with_context ( || {
191
- format ! ( "Missing gas price field in transaction {hash}" , hash = hash)
192
- } ) ?,
193
- max_fee_per_blob_gas : match ethers_tx. other . get ( "maxFeePerBlobGas" ) {
194
- Some ( max_fee_per_blob_gas) => {
195
- let max_fee_per_blob_gas =
196
- max_fee_per_blob_gas. as_str ( ) . with_context ( || {
197
- format ! (
198
- "Failed to convert `maxFeePerBlobGas` field in transaction {hash}" ,
199
- hash = hash
200
- )
201
- } ) ?;
202
-
203
- U256 :: from_str_radix ( max_fee_per_blob_gas, 16 ) ?
204
- }
205
- None => {
206
- return Err ( anyhow:: anyhow!(
207
- "Missing `maxFeePerBlobGas` field in transaction {hash}" ,
208
- hash = hash
209
- ) )
210
- }
211
- } ,
208
+ from,
209
+ to,
210
+ gas_price,
211
+ max_fee_per_blob_gas,
212
212
} )
213
213
}
214
214
}
215
215
216
- impl < ' a > TryFrom < ( & ' a BeaconBlob , u32 , H256 ) > for Blob {
216
+ impl < ' a > TryFrom < ( & ' a BeaconBlob , u32 , B256 ) > for Blob {
217
217
type Error = anyhow:: Error ;
218
218
219
219
fn try_from (
220
- ( blob_data, index, tx_hash) : ( & ' a BeaconBlob , u32 , H256 ) ,
220
+ ( blob_data, index, tx_hash) : ( & ' a BeaconBlob , u32 , B256 ) ,
221
221
) -> Result < Self , Self :: Error > {
222
222
Ok ( Self {
223
223
tx_hash,
@@ -230,9 +230,9 @@ impl<'a> TryFrom<(&'a BeaconBlob, u32, H256)> for Blob {
230
230
}
231
231
}
232
232
233
- impl < ' a > From < ( & ' a BeaconBlob , & ' a H256 , usize , & ' a H256 ) > for Blob {
233
+ impl < ' a > From < ( & ' a BeaconBlob , & ' a B256 , usize , & ' a B256 ) > for Blob {
234
234
fn from (
235
- ( blob_data, versioned_hash, index, tx_hash) : ( & ' a BeaconBlob , & ' a H256 , usize , & ' a H256 ) ,
235
+ ( blob_data, versioned_hash, index, tx_hash) : ( & ' a BeaconBlob , & ' a B256 , usize , & ' a B256 ) ,
236
236
) -> Self {
237
237
Self {
238
238
tx_hash : * tx_hash,
0 commit comments