@@ -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;
@@ -262,7 +261,7 @@ impl EthereumAdapter {
262
261
client : _,
263
262
metrics : _,
264
263
provider : _,
265
- rpc_url,
264
+ url : rpc_url,
266
265
} => rpc_url. clone ( ) ,
267
266
Transport :: IPC ( _ipc) => todo ! ( ) ,
268
267
Transport :: WS ( _web_socket) => todo ! ( ) ,
@@ -649,6 +648,14 @@ impl EthereumAdapter {
649
648
}
650
649
}
651
650
651
+ fn block_ptr_to_alloy_block_id ( & self , block_ptr : & BlockPtr ) -> alloy_rpc_types:: BlockId {
652
+ if !self . supports_eip_1898 {
653
+ alloy_rpc_types:: BlockId :: number ( block_ptr. number as u64 )
654
+ } else {
655
+ alloy_rpc_types:: BlockId :: hash ( B256 :: new ( * block_ptr. hash_as_h256 ( ) . as_fixed_bytes ( ) ) )
656
+ }
657
+ }
658
+
652
659
async fn code (
653
660
& self ,
654
661
logger : & Logger ,
@@ -687,13 +694,13 @@ impl EthereumAdapter {
687
694
async fn balance (
688
695
& self ,
689
696
logger : & Logger ,
690
- address : Address ,
697
+ address : alloy :: primitives :: Address ,
691
698
block_ptr : BlockPtr ,
692
- ) -> Result < U256 , EthereumRpcError > {
693
- let web3 = self . web3 . clone ( ) ;
699
+ ) -> Result < alloy :: primitives :: U256 , EthereumRpcError > {
700
+ let alloy = self . alloy . clone ( ) ;
694
701
let logger = Logger :: new ( & logger, o ! ( "provider" => self . provider. clone( ) ) ) ;
695
702
696
- let block_id = self . block_ptr_to_id ( & block_ptr) ;
703
+ let block_id = self . block_ptr_to_alloy_block_id ( & block_ptr) ;
697
704
let retry_log_message = format ! ( "eth_getBalance RPC call for block {}" , block_ptr) ;
698
705
699
706
retry ( retry_log_message, & logger)
@@ -705,13 +712,12 @@ impl EthereumAdapter {
705
712
. limit ( ENV_VARS . request_retries )
706
713
. timeout_secs ( ENV_VARS . json_rpc_timeout . as_secs ( ) )
707
714
. run ( move || {
708
- let web3 = web3 . cheap_clone ( ) ;
715
+ let alloy = alloy . cheap_clone ( ) ;
709
716
async move {
710
- let result: Result < U256 , web3:: Error > =
711
- web3. eth ( ) . balance ( address, Some ( block_id) ) . boxed ( ) . await ;
717
+ let result = alloy. get_balance ( address) . block_id ( block_id) . await ;
712
718
match result {
713
719
Ok ( balance) => Ok ( balance) ,
714
- Err ( err) => Err ( EthereumRpcError :: Web3Error ( err) ) ,
720
+ Err ( err) => Err ( EthereumRpcError :: AlloyError ( err) ) ,
715
721
}
716
722
}
717
723
} )
@@ -1508,9 +1514,9 @@ impl EthereumAdapterTrait for EthereumAdapter {
1508
1514
async fn get_balance (
1509
1515
& self ,
1510
1516
logger : & Logger ,
1511
- address : H160 ,
1517
+ address : alloy :: primitives :: Address ,
1512
1518
block_ptr : BlockPtr ,
1513
- ) -> Result < U256 , EthereumRpcError > {
1519
+ ) -> Result < alloy :: primitives :: U256 , EthereumRpcError > {
1514
1520
debug ! (
1515
1521
logger, "eth_getBalance" ;
1516
1522
"address" => format!( "{}" , address) ,
0 commit comments