1
1
use anyhow:: { anyhow, Error } ;
2
2
use anyhow:: { ensure, Context } ;
3
- use graph:: abi;
4
3
use graph:: abi:: EventExt ;
5
4
use graph:: abi:: FunctionExt ;
6
5
use graph:: blockchain:: { BlockPtr , TriggerWithHandler } ;
@@ -19,8 +18,11 @@ use graph::env::ENV_VARS;
19
18
use graph:: futures03:: future:: try_join;
20
19
use graph:: futures03:: stream:: FuturesOrdered ;
21
20
use graph:: futures03:: TryStreamExt ;
22
- use graph:: prelude:: { Link , SubgraphManifestValidationError } ;
21
+ use graph:: prelude:: alloy:: primitives:: { Address , B256 } ;
22
+ use graph:: prelude:: alloy:: rpc:: types:: Log ;
23
+ use graph:: prelude:: { alloy, b256_to_h256, Link , SubgraphManifestValidationError } ;
23
24
use graph:: slog:: { debug, error, o, trace} ;
25
+ use graph:: { abi, alloy_todo} ;
24
26
use itertools:: Itertools ;
25
27
use serde:: de:: Error as ErrorD ;
26
28
use serde:: { Deserialize , Deserializer } ;
@@ -35,7 +37,7 @@ use graph::{
35
37
blockchain:: { self , Blockchain } ,
36
38
prelude:: {
37
39
async_trait, serde_json, warn,
38
- web3:: types:: { Address , Log , Transaction , H160 , H256 } ,
40
+ web3:: types:: { H160 , H256 } ,
39
41
BlockNumber , CheapClone , EthereumCall , LightEthereumBlock , LightEthereumBlockExt ,
40
42
LinkResolver , Logger ,
41
43
} ,
@@ -462,7 +464,7 @@ impl DataSource {
462
464
} )
463
465
}
464
466
465
- fn handlers_for_log ( & self , log : & Log ) -> Vec < MappingEventHandler > {
467
+ fn handlers_for_log ( & self , log : & alloy :: rpc :: types :: Log ) -> Vec < MappingEventHandler > {
466
468
self . mapping
467
469
. event_handlers
468
470
. iter ( )
@@ -640,7 +642,7 @@ impl DataSource {
640
642
return true ;
641
643
} ;
642
644
643
- ds_address == * trigger_address
645
+ ds_address == trigger_address
644
646
}
645
647
646
648
/// Checks if `trigger` matches this data source, and if so decodes it into a `MappingTrigger`.
@@ -748,17 +750,18 @@ impl DataSource {
748
750
// See also ca0edc58-0ec5-4c89-a7dd-2241797f5e50.
749
751
// There is another special case in zkSync-era, where the transaction hash in this case would be zero
750
752
// See https://docs.zksync.io/zk-stack/concepts/blocks.html#fictive-l2-block-finalizing-the-batch
751
- let transaction = if log. transaction_hash == block. hash_h256 ( )
752
- || log. transaction_hash == Some ( H256 :: zero ( ) )
753
+ let transaction = if log. transaction_hash == Some ( block. hash ( ) )
754
+ || log. transaction_hash == Some ( B256 :: ZERO )
753
755
{
754
- Transaction {
755
- hash : log. transaction_hash . unwrap ( ) ,
756
- block_hash : block. hash_h256 ( ) ,
757
- block_number : block. number_web3_u64 ( ) ,
758
- transaction_index : log. transaction_index ,
759
- from : Some ( H160 :: zero ( ) ) ,
760
- ..Transaction :: default ( )
761
- }
756
+ // Transaction {
757
+ // hash: log.transaction_hash.unwrap(),
758
+ // block_hash: block.hash_h256(),
759
+ // block_number: block.number_web3_u64(),
760
+ // transaction_index: log.transaction_index,
761
+ // from: Some(H160::zero()),
762
+ // ..Transaction::default()
763
+ // }
764
+ alloy_todo ! ( )
762
765
} else {
763
766
// This is the general case where the log's transaction hash does not match the block's hash
764
767
// and is not a special zero hash, implying a real transaction associated with this log.
@@ -1438,12 +1441,12 @@ pub struct MappingCallHandler {
1438
1441
#[ derive( Clone , Debug , Eq , PartialEq , Deserialize ) ]
1439
1442
pub struct UnresolvedMappingEventHandler {
1440
1443
pub event : String ,
1441
- pub topic0 : Option < H256 > ,
1442
- #[ serde( deserialize_with = "deserialize_h256_vec " , default ) ]
1443
- pub topic1 : Option < Vec < H256 > > ,
1444
- #[ serde( deserialize_with = "deserialize_h256_vec " , default ) ]
1445
- pub topic2 : Option < Vec < H256 > > ,
1446
- #[ serde( deserialize_with = "deserialize_h256_vec " , default ) ]
1444
+ pub topic0 : Option < B256 > ,
1445
+ #[ serde( deserialize_with = "deserialize_b256_vec " , default ) ]
1446
+ pub topic1 : Option < Vec < B256 > > ,
1447
+ #[ serde( deserialize_with = "deserialize_b256_vec " , default ) ]
1448
+ pub topic2 : Option < Vec < B256 > > ,
1449
+ #[ serde( deserialize_with = "deserialize_b256_vec " , default ) ]
1447
1450
pub topic3 : Option < Vec < H256 > > ,
1448
1451
pub handler : String ,
1449
1452
#[ serde( default ) ]
@@ -1488,27 +1491,27 @@ pub struct MappingEventHandler {
1488
1491
}
1489
1492
1490
1493
// Custom deserializer for H256 fields that removes the '0x' prefix before parsing
1491
- fn deserialize_h256_vec < ' de , D > ( deserializer : D ) -> Result < Option < Vec < H256 > > , D :: Error >
1494
+ fn deserialize_b256_vec < ' de , D > ( deserializer : D ) -> Result < Option < Vec < H256 > > , D :: Error >
1492
1495
where
1493
1496
D : Deserializer < ' de > ,
1494
1497
{
1495
1498
let s: Option < Vec < String > > = Option :: deserialize ( deserializer) ?;
1496
1499
1497
1500
match s {
1498
1501
Some ( vec) => {
1499
- let mut h256_vec = Vec :: new ( ) ;
1502
+ let mut b256_vec = Vec :: new ( ) ;
1500
1503
for hex_str in vec {
1501
1504
// Remove '0x' prefix if present
1502
1505
let clean_hex_str = hex_str. trim_start_matches ( "0x" ) ;
1503
1506
// Ensure the hex string is 64 characters long, after removing '0x'
1504
1507
let padded_hex_str = format ! ( "{:0>64}" , clean_hex_str) ;
1505
1508
// Parse the padded string into H256, handling potential errors
1506
- h256_vec . push (
1507
- H256 :: from_str ( & padded_hex_str)
1508
- . map_err ( |e| D :: Error :: custom ( format ! ( "Failed to parse H256 : {}" , e) ) ) ?,
1509
+ b256_vec . push (
1510
+ B256 :: from_str ( & padded_hex_str)
1511
+ . map_err ( |e| D :: Error :: custom ( format ! ( "Failed to parse B256 : {}" , e) ) ) ?,
1509
1512
) ;
1510
1513
}
1511
- Ok ( Some ( h256_vec ) )
1514
+ Ok ( Some ( b256_vec ) )
1512
1515
}
1513
1516
None => Ok ( None ) ,
1514
1517
}
@@ -1521,16 +1524,16 @@ impl MappingEventHandler {
1521
1524
}
1522
1525
1523
1526
pub fn matches ( & self , log : & Log ) -> bool {
1524
- let matches_topic = |index : usize , topic_opt : & Option < Vec < H256 > > | -> bool {
1527
+ let matches_topic = |index : usize , topic_opt : & Option < Vec < B256 > > | -> bool {
1525
1528
topic_opt. as_ref ( ) . map_or ( true , |topic_vec| {
1526
- log. topics
1529
+ log. topics ( )
1527
1530
. get ( index)
1528
1531
. map_or ( false , |log_topic| topic_vec. contains ( log_topic) )
1529
1532
} )
1530
1533
} ;
1531
1534
1532
- if let Some ( topic0) = log. topics . get ( 0 ) {
1533
- return self . topic0 ( ) == * topic0
1535
+ if let Some ( topic0) = log. topics ( ) . get ( 0 ) {
1536
+ return self . topic0 ( ) == b256_to_h256 ( * topic0)
1534
1537
&& matches_topic ( 1 , & self . topic1 )
1535
1538
&& matches_topic ( 2 , & self . topic2 )
1536
1539
&& matches_topic ( 3 , & self . topic3 ) ;
0 commit comments