@@ -20,6 +20,7 @@ use graph::futures03::{
20
20
self , compat:: Future01CompatExt , FutureExt , StreamExt , TryFutureExt , TryStreamExt ,
21
21
} ;
22
22
use graph:: prelude:: alloy;
23
+ use graph:: prelude:: alloy:: rpc:: types:: { TransactionInput , TransactionRequest } ;
23
24
use graph:: prelude:: tokio:: try_join;
24
25
use graph:: slog:: o;
25
26
use graph:: tokio:: sync:: RwLock ;
@@ -31,10 +32,7 @@ use graph::{
31
32
async_trait, debug, error, hex, info, retry, serde_json as json, trace, warn,
32
33
web3:: {
33
34
self ,
34
- types:: {
35
- BlockId , Bytes , CallRequest , Filter , FilterBuilder , Log , Transaction ,
36
- TransactionReceipt , H256 ,
37
- } ,
35
+ types:: { BlockId , Filter , FilterBuilder , Log , Transaction , TransactionReceipt , H256 } ,
38
36
} ,
39
37
BlockNumber , ChainStore , CheapClone , DynTryFuture , Error , EthereumCallCache , Logger ,
40
38
TimeoutError ,
@@ -514,18 +512,7 @@ impl EthereumAdapter {
514
512
. boxed ( )
515
513
}
516
514
517
- // Method to determine block_id based on support for EIP-1898
518
- fn block_ptr_to_id ( & self , block_ptr : & BlockPtr ) -> BlockId {
519
- // Ganache does not support calls by block hash.
520
- // See https://github.com/trufflesuite/ganache-cli/issues/973
521
- if !self . supports_eip_1898 {
522
- BlockId :: Number ( block_ptr. number . into ( ) )
523
- } else {
524
- BlockId :: Hash ( block_ptr. hash_as_h256 ( ) )
525
- }
526
- }
527
-
528
- fn block_ptr_to_alloy_block_id ( & self , block_ptr : & BlockPtr ) -> alloy:: rpc:: types:: BlockId {
515
+ fn block_ptr_to_id ( & self , block_ptr : & BlockPtr ) -> alloy:: rpc:: types:: BlockId {
529
516
if !self . supports_eip_1898 {
530
517
alloy:: rpc:: types:: BlockId :: number ( block_ptr. number as u64 )
531
518
} else {
@@ -544,7 +531,7 @@ impl EthereumAdapter {
544
531
let alloy = self . alloy . clone ( ) ;
545
532
let logger = Logger :: new ( & logger, o ! ( "provider" => self . provider. clone( ) ) ) ;
546
533
547
- let block_id = self . block_ptr_to_alloy_block_id ( & block_ptr) ;
534
+ let block_id = self . block_ptr_to_id ( & block_ptr) ;
548
535
let retry_log_message = format ! ( "eth_getCode RPC call for block {}" , block_ptr) ;
549
536
550
537
retry ( retry_log_message, & logger)
@@ -578,7 +565,7 @@ impl EthereumAdapter {
578
565
let alloy = self . alloy . clone ( ) ;
579
566
let logger = Logger :: new ( & logger, o ! ( "provider" => self . provider. clone( ) ) ) ;
580
567
581
- let block_id = self . block_ptr_to_alloy_block_id ( & block_ptr) ;
568
+ let block_id = self . block_ptr_to_id ( & block_ptr) ;
582
569
let retry_log_message = format ! ( "eth_getBalance RPC call for block {}" , block_ptr) ;
583
570
584
571
retry ( retry_log_message, & logger)
@@ -610,33 +597,33 @@ impl EthereumAdapter {
610
597
block_ptr : BlockPtr ,
611
598
gas : Option < u32 > ,
612
599
) -> Result < call:: Retval , ContractCallError > {
613
- let web3 = self . web3 . clone ( ) ;
600
+ let alloy = self . alloy . clone ( ) ;
614
601
let logger = Logger :: new ( & logger, o ! ( "provider" => self . provider. clone( ) ) ) ;
615
602
616
- let block_id = self . block_ptr_to_id ( & block_ptr) ;
603
+ let alloy_block_id = self . block_ptr_to_id ( & block_ptr) ;
617
604
let retry_log_message = format ! ( "eth_call RPC call for block {}" , block_ptr) ;
618
605
retry ( retry_log_message, & logger)
619
606
. redact_log_urls ( true )
620
607
. limit ( ENV_VARS . request_retries )
621
608
. timeout_secs ( ENV_VARS . json_rpc_timeout . as_secs ( ) )
622
609
. run ( move || {
623
610
let call_data = call_data. clone ( ) ;
624
- let web3 = web3 . cheap_clone ( ) ;
611
+ let alloy = alloy . cheap_clone ( ) ;
625
612
let logger = logger. cheap_clone ( ) ;
626
613
async move {
627
- let req = CallRequest {
628
- to : Some ( call_data . address ) ,
629
- gas : gas . map ( |val| web3 :: types :: U256 :: from ( val ) ) ,
630
- data : Some ( Bytes :: from ( call_data . encoded_call . to_vec ( ) ) ) ,
631
- from : None ,
632
- gas_price : None ,
633
- value : None ,
634
- access_list : None ,
635
- max_fee_per_gas : None ,
636
- max_priority_fee_per_gas : None ,
637
- transaction_type : None ,
638
- } ;
639
- let result = web3 . eth ( ) . call ( req, Some ( block_id ) ) . boxed ( ) . await ;
614
+ let mut req = TransactionRequest :: default ( )
615
+ . input ( TransactionInput :: both ( alloy :: primitives :: Bytes :: from (
616
+ call_data . encoded_call . to_vec ( ) ,
617
+ ) ) )
618
+ . to ( alloy :: primitives :: Address :: from (
619
+ call_data . address . as_fixed_bytes ( ) ,
620
+ ) ) ;
621
+
622
+ if let Some ( gas ) = gas {
623
+ req = req . gas_limit ( gas as u64 ) ;
624
+ }
625
+
626
+ let result = alloy . call ( req) . block ( alloy_block_id ) . await ;
640
627
641
628
match result {
642
629
Ok ( bytes) => Ok ( call:: Retval :: Value ( scalar:: Bytes :: from ( bytes) ) ) ,
0 commit comments