1- use alloy:: primitives:: { B256 , B64 } ;
1+ use alloy:: primitives:: { TxKind , B256 , B64 } ;
22use alloy:: providers:: { Provider , ProviderBuilder } ;
3- use alloy_rpc_types:: { BlockTransactions , FilterBlockOption } ;
3+ use alloy_rpc_types:: { BlockTransactions , FilterBlockOption , TransactionInput , TransactionRequest } ;
44use futures03:: { future:: BoxFuture , stream:: FuturesUnordered } ;
55use graph:: abi;
66use graph:: abi:: DynSolValueExt ;
@@ -552,17 +552,30 @@ impl EthereumAdapter {
552552 }
553553 }
554554
555+ // Method to determine block_id based on support for EIP-1898
556+ fn block_ptr_to_id2 ( & self , block_ptr : & BlockPtr ) -> alloy_rpc_types:: BlockId {
557+ // Ganache does not support calls by block hash.
558+ // See https://github.com/trufflesuite/ganache-cli/issues/973
559+ if !self . supports_eip_1898 {
560+ alloy_rpc_types:: BlockId :: number ( block_ptr. number as u64 )
561+ } else {
562+ alloy_rpc_types:: BlockId :: hash ( h256_to_b256 ( & block_ptr. hash_as_h256 ( ) ) )
563+ }
564+ }
565+
555566 async fn code (
556567 & self ,
557568 logger : & Logger ,
558569 address : Address ,
559570 block_ptr : BlockPtr ,
560571 ) -> Result < Bytes , EthereumRpcError > {
561- info ! ( logger, "!!!! code" ) ;
562572 let web3 = self . web3 . clone ( ) ;
573+ let alloy = self . alloy . clone ( ) ;
563574 let logger = Logger :: new ( & logger, o ! ( "provider" => self . provider. clone( ) ) ) ;
564575
565576 let block_id = self . block_ptr_to_id ( & block_ptr) ;
577+ let block_id2 = self . block_ptr_to_id2 ( & block_ptr) ;
578+ let address2 = h160_to_address ( & address) ;
566579 let retry_log_message = format ! ( "eth_getCode RPC call for block {}" , block_ptr) ;
567580
568581 retry ( retry_log_message, & logger)
@@ -575,11 +588,20 @@ impl EthereumAdapter {
575588 . timeout_secs ( ENV_VARS . json_rpc_timeout . as_secs ( ) )
576589 . run ( move || {
577590 let web3 = web3. cheap_clone ( ) ;
591+ let alloy = alloy. clone ( ) ;
578592 async move {
579593 let result: Result < Bytes , web3:: Error > =
580594 web3. eth ( ) . code ( address, Some ( block_id) ) . boxed ( ) . await ;
595+ let result2 = alloy
596+ . get_code_at ( address2)
597+ . block_id ( block_id2)
598+ . await
599+ . map ( bytes_to_bytes) ;
581600 match result {
582- Ok ( code) => Ok ( code) ,
601+ Ok ( code) => {
602+ assert_eq ! ( result2. unwrap( ) , code) ;
603+ Ok ( code)
604+ }
583605 Err ( err) => Err ( EthereumRpcError :: Web3Error ( err) ) ,
584606 }
585607 }
@@ -594,11 +616,13 @@ impl EthereumAdapter {
594616 address : Address ,
595617 block_ptr : BlockPtr ,
596618 ) -> Result < U256 , EthereumRpcError > {
597- info ! ( logger, "!!!! balances" ) ;
598619 let web3 = self . web3 . clone ( ) ;
620+ let alloy = self . alloy . clone ( ) ;
599621 let logger = Logger :: new ( & logger, o ! ( "provider" => self . provider. clone( ) ) ) ;
600622
601623 let block_id = self . block_ptr_to_id ( & block_ptr) ;
624+ let block_id2 = self . block_ptr_to_id2 ( & block_ptr) ;
625+ let address2 = h160_to_address ( & address) ;
602626 let retry_log_message = format ! ( "eth_getBalance RPC call for block {}" , block_ptr) ;
603627
604628 retry ( retry_log_message, & logger)
@@ -611,11 +635,20 @@ impl EthereumAdapter {
611635 . timeout_secs ( ENV_VARS . json_rpc_timeout . as_secs ( ) )
612636 . run ( move || {
613637 let web3 = web3. cheap_clone ( ) ;
638+ let alloy = alloy. clone ( ) ;
614639 async move {
615640 let result: Result < U256 , web3:: Error > =
616641 web3. eth ( ) . balance ( address, Some ( block_id) ) . boxed ( ) . await ;
642+ let result2 = alloy
643+ . get_balance ( address2)
644+ . block_id ( block_id2)
645+ . await
646+ . map ( u256_to_u256) ;
617647 match result {
618- Ok ( balance) => Ok ( balance) ,
648+ Ok ( balance) => {
649+ assert_eq ! ( result2. unwrap( ) , balance) ;
650+ Ok ( balance)
651+ }
619652 Err ( err) => Err ( EthereumRpcError :: Web3Error ( err) ) ,
620653 }
621654 }
@@ -631,13 +664,13 @@ impl EthereumAdapter {
631664 block_ptr : BlockPtr ,
632665 gas : Option < u32 > ,
633666 ) -> Result < call:: Retval , ContractCallError > {
634- info ! ( logger, "!!!! call" ) ;
635667 fn reverted ( logger : & Logger , reason : & str ) -> Result < call:: Retval , ContractCallError > {
636668 info ! ( logger, "Contract call reverted" ; "reason" => reason) ;
637669 Ok ( call:: Retval :: Null )
638670 }
639671
640672 let web3 = self . web3 . clone ( ) ;
673+ let alloy = self . alloy . clone ( ) ;
641674 let logger = Logger :: new ( & logger, o ! ( "provider" => self . provider. clone( ) ) ) ;
642675
643676 let block_id = self . block_ptr_to_id ( & block_ptr) ;
@@ -649,6 +682,7 @@ impl EthereumAdapter {
649682 . run ( move || {
650683 let call_data = call_data. clone ( ) ;
651684 let web3 = web3. cheap_clone ( ) ;
685+ let alloy = alloy. clone ( ) ;
652686 let logger = logger. cheap_clone ( ) ;
653687 async move {
654688 let req = CallRequest {
@@ -664,6 +698,33 @@ impl EthereumAdapter {
664698 transaction_type : None ,
665699 } ;
666700 let result = web3. eth ( ) . call ( req, Some ( block_id) ) . boxed ( ) . await ;
701+ let gas = gas. map ( |val| val as u64 ) ;
702+ let to = Some ( TxKind :: from ( h160_to_address ( & call_data. address ) ) ) ;
703+ let input = TransactionInput {
704+ input : None ,
705+ data : Some ( alloy:: primitives:: Bytes :: from (
706+ call_data. encoded_call . to_vec ( ) ,
707+ ) ) ,
708+ } ;
709+ let tx_req = TransactionRequest {
710+ from : None ,
711+ to,
712+ gas_price : None ,
713+ max_fee_per_gas : None ,
714+ max_priority_fee_per_gas : None ,
715+ max_fee_per_blob_gas : None ,
716+ gas,
717+ value : None ,
718+ input,
719+ nonce : None ,
720+ chain_id : None ,
721+ access_list : None ,
722+ transaction_type : None ,
723+ blob_versioned_hashes : None ,
724+ sidecar : None ,
725+ authorization_list : None ,
726+ } ;
727+ let result2 = alloy. call ( tx_req) . await . map ( bytes_to_bytes) ;
667728
668729 // Try to check if the call was reverted. The JSON-RPC response for reverts is
669730 // not standardized, so we have ad-hoc checks for each Ethereum client.
@@ -728,7 +789,10 @@ impl EthereumAdapter {
728789
729790 match result {
730791 // A successful response.
731- Ok ( bytes) => Ok ( call:: Retval :: Value ( scalar:: Bytes :: from ( bytes) ) ) ,
792+ Ok ( bytes) => {
793+ assert_eq ! ( result2. unwrap( ) , bytes) ;
794+ Ok ( call:: Retval :: Value ( scalar:: Bytes :: from ( bytes) ) )
795+ }
732796
733797 // Check for Geth revert.
734798 Err ( web3:: Error :: Rpc ( rpc_error) )
@@ -1184,7 +1248,6 @@ impl EthereumAdapter {
11841248 + std:: marker:: Send ,
11851249 > ,
11861250 > {
1187- info ! ( logger, "!!!! blocks_matching_polling_intervals" ) ;
11881251 // Create a HashMap of block numbers to Vec<EthereumBlockTriggerType>
11891252 let matching_blocks = ( from..=to)
11901253 . filter_map ( |block_number| {
@@ -1979,7 +2042,6 @@ impl EthereumAdapterTrait for EthereumAdapter {
19792042 calls : & [ & ContractCall ] ,
19802043 cache : Arc < dyn EthereumCallCache > ,
19812044 ) -> Result < Vec < ( Option < Vec < abi:: DynSolValue > > , call:: Source ) > , ContractCallError > {
1982- info ! ( logger, "!!!! contract_calls" ) ;
19832045 fn as_req (
19842046 logger : & Logger ,
19852047 call : & ContractCall ,
@@ -3254,6 +3316,10 @@ fn convert_bloom(logs_bloom: &alloy::primitives::Bloom) -> H2048 {
32543316 let bytes: [ u8 ; 256 ] = logs_bloom. as_slice ( ) [ 0 ..256 ] . try_into ( ) . unwrap ( ) ;
32553317 H2048 :: from ( bytes)
32563318}
3319+ fn bytes_to_bytes ( in_data : alloy:: primitives:: Bytes ) -> Bytes {
3320+ let slice = in_data. iter ( ) . as_slice ( ) ;
3321+ Bytes :: from ( slice)
3322+ }
32573323
32583324fn convert_topic (
32593325 h256s : & Option < Vec < H256 > > ,
0 commit comments