@@ -22,7 +22,6 @@ use graph::futures03::{
22
22
self , compat:: Future01CompatExt , FutureExt , StreamExt , TryFutureExt , TryStreamExt ,
23
23
} ;
24
24
use graph:: prelude:: tokio:: try_join;
25
- use graph:: prelude:: web3:: types:: U256 ;
26
25
use graph:: slog:: o;
27
26
use graph:: tokio:: sync:: RwLock ;
28
27
use graph:: tokio:: time:: timeout;
@@ -134,7 +133,7 @@ impl EthereumAdapter {
134
133
client : _,
135
134
metrics : _,
136
135
provider : _,
137
- rpc_url,
136
+ url : rpc_url,
138
137
} => rpc_url. clone ( ) ,
139
138
Transport :: IPC ( _ipc) => todo ! ( ) ,
140
139
Transport :: WS ( _web_socket) => todo ! ( ) ,
@@ -521,6 +520,14 @@ impl EthereumAdapter {
521
520
}
522
521
}
523
522
523
+ fn block_ptr_to_alloy_block_id ( & self , block_ptr : & BlockPtr ) -> alloy_rpc_types:: BlockId {
524
+ if !self . supports_eip_1898 {
525
+ alloy_rpc_types:: BlockId :: number ( block_ptr. number as u64 )
526
+ } else {
527
+ alloy_rpc_types:: BlockId :: hash ( B256 :: new ( * block_ptr. hash_as_h256 ( ) . as_fixed_bytes ( ) ) )
528
+ }
529
+ }
530
+
524
531
async fn code (
525
532
& self ,
526
533
logger : & Logger ,
@@ -559,13 +566,13 @@ impl EthereumAdapter {
559
566
async fn balance (
560
567
& self ,
561
568
logger : & Logger ,
562
- address : Address ,
569
+ address : alloy :: primitives :: Address ,
563
570
block_ptr : BlockPtr ,
564
- ) -> Result < U256 , EthereumRpcError > {
565
- let web3 = self . web3 . clone ( ) ;
571
+ ) -> Result < alloy :: primitives :: U256 , EthereumRpcError > {
572
+ let alloy = self . alloy . clone ( ) ;
566
573
let logger = Logger :: new ( & logger, o ! ( "provider" => self . provider. clone( ) ) ) ;
567
574
568
- let block_id = self . block_ptr_to_id ( & block_ptr) ;
575
+ let block_id = self . block_ptr_to_alloy_block_id ( & block_ptr) ;
569
576
let retry_log_message = format ! ( "eth_getBalance RPC call for block {}" , block_ptr) ;
570
577
571
578
retry ( retry_log_message, & logger)
@@ -577,13 +584,12 @@ impl EthereumAdapter {
577
584
. limit ( ENV_VARS . request_retries )
578
585
. timeout_secs ( ENV_VARS . json_rpc_timeout . as_secs ( ) )
579
586
. run ( move || {
580
- let web3 = web3 . cheap_clone ( ) ;
587
+ let alloy = alloy . cheap_clone ( ) ;
581
588
async move {
582
- let result: Result < U256 , web3:: Error > =
583
- web3. eth ( ) . balance ( address, Some ( block_id) ) . boxed ( ) . await ;
589
+ let result = alloy. get_balance ( address) . block_id ( block_id) . await ;
584
590
match result {
585
591
Ok ( balance) => Ok ( balance) ,
586
- Err ( err) => Err ( EthereumRpcError :: Web3Error ( err) ) ,
592
+ Err ( err) => Err ( EthereumRpcError :: AlloyError ( err) ) ,
587
593
}
588
594
}
589
595
} )
@@ -1493,9 +1499,9 @@ impl EthereumAdapterTrait for EthereumAdapter {
1493
1499
async fn get_balance (
1494
1500
& self ,
1495
1501
logger : & Logger ,
1496
- address : H160 ,
1502
+ address : alloy :: primitives :: Address ,
1497
1503
block_ptr : BlockPtr ,
1498
- ) -> Result < U256 , EthereumRpcError > {
1504
+ ) -> Result < alloy :: primitives :: U256 , EthereumRpcError > {
1499
1505
debug ! (
1500
1506
logger, "eth_getBalance" ;
1501
1507
"address" => format!( "{}" , address) ,
0 commit comments