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 } ;
@@ -16,8 +15,11 @@ use graph::env::ENV_VARS;
16
15
use graph:: futures03:: future:: try_join;
17
16
use graph:: futures03:: stream:: FuturesOrdered ;
18
17
use graph:: futures03:: TryStreamExt ;
19
- use graph:: prelude:: { Link , SubgraphManifestValidationError } ;
18
+ use graph:: prelude:: alloy:: primitives:: { Address , B256 } ;
19
+ use graph:: prelude:: alloy:: rpc:: types:: Log ;
20
+ use graph:: prelude:: { alloy, b256_to_h256, Link , SubgraphManifestValidationError } ;
20
21
use graph:: slog:: { debug, error, o, trace} ;
22
+ use graph:: { abi, alloy_todo} ;
21
23
use itertools:: Itertools ;
22
24
use serde:: de:: Error as ErrorD ;
23
25
use serde:: { Deserialize , Deserializer } ;
@@ -32,7 +34,7 @@ use graph::{
32
34
blockchain:: { self , Blockchain } ,
33
35
prelude:: {
34
36
async_trait, serde_json, warn,
35
- web3:: types:: { Address , Log , Transaction , H160 , H256 } ,
37
+ web3:: types:: { H160 , H256 } ,
36
38
BlockNumber , CheapClone , EthereumCall , LightEthereumBlock , LightEthereumBlockExt ,
37
39
LinkResolver , Logger ,
38
40
} ,
@@ -459,7 +461,7 @@ impl DataSource {
459
461
} )
460
462
}
461
463
462
- fn handlers_for_log ( & self , log : & Log ) -> Vec < MappingEventHandler > {
464
+ fn handlers_for_log ( & self , log : & alloy :: rpc :: types :: Log ) -> Vec < MappingEventHandler > {
463
465
self . mapping
464
466
. event_handlers
465
467
. iter ( )
@@ -637,7 +639,7 @@ impl DataSource {
637
639
return true ;
638
640
} ;
639
641
640
- ds_address == * trigger_address
642
+ ds_address == trigger_address
641
643
}
642
644
643
645
/// Checks if `trigger` matches this data source, and if so decodes it into a `MappingTrigger`.
@@ -745,17 +747,18 @@ impl DataSource {
745
747
// See also ca0edc58-0ec5-4c89-a7dd-2241797f5e50.
746
748
// There is another special case in zkSync-era, where the transaction hash in this case would be zero
747
749
// See https://docs.zksync.io/zk-stack/concepts/blocks.html#fictive-l2-block-finalizing-the-batch
748
- let transaction = if log. transaction_hash == block. hash_h256 ( )
749
- || log. transaction_hash == Some ( H256 :: zero ( ) )
750
+ let transaction = if log. transaction_hash == Some ( block. hash ( ) )
751
+ || log. transaction_hash == Some ( B256 :: ZERO )
750
752
{
751
- Transaction {
752
- hash : log. transaction_hash . unwrap ( ) ,
753
- block_hash : block. hash_h256 ( ) ,
754
- block_number : block. number_web3_u64 ( ) ,
755
- transaction_index : log. transaction_index ,
756
- from : Some ( H160 :: zero ( ) ) ,
757
- ..Transaction :: default ( )
758
- }
753
+ // Transaction {
754
+ // hash: log.transaction_hash.unwrap(),
755
+ // block_hash: block.hash_h256(),
756
+ // block_number: block.number_web3_u64(),
757
+ // transaction_index: log.transaction_index,
758
+ // from: Some(H160::zero()),
759
+ // ..Transaction::default()
760
+ // }
761
+ alloy_todo ! ( )
759
762
} else {
760
763
// This is the general case where the log's transaction hash does not match the block's hash
761
764
// and is not a special zero hash, implying a real transaction associated with this log.
@@ -1405,12 +1408,12 @@ pub struct MappingCallHandler {
1405
1408
#[ derive( Clone , Debug , Hash , Eq , PartialEq , Deserialize ) ]
1406
1409
pub struct MappingEventHandler {
1407
1410
pub event : String ,
1408
- pub topic0 : Option < H256 > ,
1409
- #[ serde( deserialize_with = "deserialize_h256_vec " , default ) ]
1410
- pub topic1 : Option < Vec < H256 > > ,
1411
- #[ serde( deserialize_with = "deserialize_h256_vec " , default ) ]
1412
- pub topic2 : Option < Vec < H256 > > ,
1413
- #[ serde( deserialize_with = "deserialize_h256_vec " , default ) ]
1411
+ pub topic0 : Option < B256 > ,
1412
+ #[ serde( deserialize_with = "deserialize_b256_vec " , default ) ]
1413
+ pub topic1 : Option < Vec < B256 > > ,
1414
+ #[ serde( deserialize_with = "deserialize_b256_vec " , default ) ]
1415
+ pub topic2 : Option < Vec < B256 > > ,
1416
+ #[ serde( deserialize_with = "deserialize_b256_vec " , default ) ]
1414
1417
pub topic3 : Option < Vec < H256 > > ,
1415
1418
pub handler : String ,
1416
1419
#[ serde( default ) ]
@@ -1420,27 +1423,27 @@ pub struct MappingEventHandler {
1420
1423
}
1421
1424
1422
1425
// Custom deserializer for H256 fields that removes the '0x' prefix before parsing
1423
- fn deserialize_h256_vec < ' de , D > ( deserializer : D ) -> Result < Option < Vec < H256 > > , D :: Error >
1426
+ fn deserialize_b256_vec < ' de , D > ( deserializer : D ) -> Result < Option < Vec < H256 > > , D :: Error >
1424
1427
where
1425
1428
D : Deserializer < ' de > ,
1426
1429
{
1427
1430
let s: Option < Vec < String > > = Option :: deserialize ( deserializer) ?;
1428
1431
1429
1432
match s {
1430
1433
Some ( vec) => {
1431
- let mut h256_vec = Vec :: new ( ) ;
1434
+ let mut b256_vec = Vec :: new ( ) ;
1432
1435
for hex_str in vec {
1433
1436
// Remove '0x' prefix if present
1434
1437
let clean_hex_str = hex_str. trim_start_matches ( "0x" ) ;
1435
1438
// Ensure the hex string is 64 characters long, after removing '0x'
1436
1439
let padded_hex_str = format ! ( "{:0>64}" , clean_hex_str) ;
1437
1440
// Parse the padded string into H256, handling potential errors
1438
- h256_vec . push (
1439
- H256 :: from_str ( & padded_hex_str)
1440
- . map_err ( |e| D :: Error :: custom ( format ! ( "Failed to parse H256 : {}" , e) ) ) ?,
1441
+ b256_vec . push (
1442
+ B256 :: from_str ( & padded_hex_str)
1443
+ . map_err ( |e| D :: Error :: custom ( format ! ( "Failed to parse B256 : {}" , e) ) ) ?,
1441
1444
) ;
1442
1445
}
1443
- Ok ( Some ( h256_vec ) )
1446
+ Ok ( Some ( b256_vec ) )
1444
1447
}
1445
1448
None => Ok ( None ) ,
1446
1449
}
@@ -1453,16 +1456,16 @@ impl MappingEventHandler {
1453
1456
}
1454
1457
1455
1458
pub fn matches ( & self , log : & Log ) -> bool {
1456
- let matches_topic = |index : usize , topic_opt : & Option < Vec < H256 > > | -> bool {
1459
+ let matches_topic = |index : usize , topic_opt : & Option < Vec < B256 > > | -> bool {
1457
1460
topic_opt. as_ref ( ) . map_or ( true , |topic_vec| {
1458
- log. topics
1461
+ log. topics ( )
1459
1462
. get ( index)
1460
1463
. map_or ( false , |log_topic| topic_vec. contains ( log_topic) )
1461
1464
} )
1462
1465
} ;
1463
1466
1464
- if let Some ( topic0) = log. topics . get ( 0 ) {
1465
- return self . topic0 ( ) == * topic0
1467
+ if let Some ( topic0) = log. topics ( ) . get ( 0 ) {
1468
+ return self . topic0 ( ) == b256_to_h256 ( * topic0)
1466
1469
&& matches_topic ( 1 , & self . topic1 )
1467
1470
&& matches_topic ( 2 , & self . topic2 )
1468
1471
&& matches_topic ( 3 , & self . topic3 ) ;
0 commit comments