@@ -14,7 +14,7 @@ use graph::data_source::{
1414 UnresolvedDataSource as GraphUnresolvedDS , UnresolvedDataSourceTemplate as GraphUnresolvedDST ,
1515} ;
1616use graph:: prelude:: DeploymentHash ;
17- use graph_chain_ethereum:: Chain ;
17+ use graph_chain_ethereum:: { BlockHandlerFilter , Chain } ;
1818use semver:: Version ;
1919
2020use crate :: output:: { step, Step } ;
@@ -68,12 +68,12 @@ pub struct DataSource {
6868 pub source_address : Option < String > ,
6969 /// The ABI name referenced in `source.abi` (Ethereum data sources only).
7070 pub source_abi : Option < String > ,
71- /// Event handler names from the mapping.
72- pub event_handlers : Vec < String > ,
71+ /// Event handlers from the mapping.
72+ pub event_handlers : Vec < EventHandler > ,
7373 /// Call handler names from the mapping.
7474 pub call_handlers : Vec < String > ,
75- /// Block handler names from the mapping.
76- pub block_handlers : Vec < String > ,
75+ /// Block handlers from the mapping (with filter info for validation) .
76+ pub block_handlers : Vec < BlockHandler > ,
7777}
7878
7979impl DataSource {
@@ -94,12 +94,12 @@ pub struct Template {
9494 pub abis : Vec < Abi > ,
9595 /// The ABI name referenced in `source.abi` (Ethereum templates only).
9696 pub source_abi : Option < String > ,
97- /// Event handler names from the mapping.
98- pub event_handlers : Vec < String > ,
97+ /// Event handlers from the mapping.
98+ pub event_handlers : Vec < EventHandler > ,
9999 /// Call handler names from the mapping.
100100 pub call_handlers : Vec < String > ,
101- /// Block handler names from the mapping.
102- pub block_handlers : Vec < String > ,
101+ /// Block handlers from the mapping (with filter info for validation) .
102+ pub block_handlers : Vec < BlockHandler > ,
103103}
104104
105105impl Manifest {
@@ -116,6 +116,31 @@ pub struct Abi {
116116 pub file : String ,
117117}
118118
119+ /// An event handler with metadata needed for validation.
120+ #[ derive( Debug ) ]
121+ pub struct EventHandler {
122+ pub handler : String ,
123+ /// Whether this handler requires transaction receipts.
124+ pub receipt : bool ,
125+ /// Whether this handler has eth call declarations.
126+ pub has_call_decls : bool ,
127+ }
128+
129+ /// A block handler with filter info needed for validation.
130+ #[ derive( Debug ) ]
131+ pub struct BlockHandler {
132+ pub handler : String ,
133+ pub filter : Option < BlockHandlerFilterKind > ,
134+ }
135+
136+ /// The kind of filter on a block handler (simplified from graph-node's `BlockHandlerFilter`).
137+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
138+ pub enum BlockHandlerFilterKind {
139+ Call ,
140+ Once ,
141+ Polling ,
142+ }
143+
119144/// Load a subgraph manifest from a YAML file.
120145///
121146/// This uses graph-node's `UnresolvedSubgraphManifest::parse()` which
@@ -197,7 +222,11 @@ fn convert_data_source(ds: GraphUnresolvedDS<Chain>) -> DataSource {
197222 . mapping
198223 . event_handlers
199224 . iter ( )
200- . map ( |h| h. handler . clone ( ) )
225+ . map ( |h| EventHandler {
226+ handler : h. handler . clone ( ) ,
227+ receipt : h. receipt ,
228+ has_call_decls : !h. calls . raw_decls . is_empty ( ) ,
229+ } )
201230 . collect ( ) ,
202231 call_handlers : eth
203232 . mapping
@@ -209,7 +238,10 @@ fn convert_data_source(ds: GraphUnresolvedDS<Chain>) -> DataSource {
209238 . mapping
210239 . block_handlers
211240 . iter ( )
212- . map ( |h| h. handler . clone ( ) )
241+ . map ( |h| BlockHandler {
242+ handler : h. handler . clone ( ) ,
243+ filter : h. filter . as_ref ( ) . map ( convert_block_handler_filter) ,
244+ } )
213245 . collect ( ) ,
214246 } ,
215247 GraphUnresolvedDS :: Subgraph ( sub) => DataSource {
@@ -287,7 +319,11 @@ fn convert_template(t: GraphUnresolvedDST<Chain>) -> Template {
287319 . mapping
288320 . event_handlers
289321 . iter ( )
290- . map ( |h| h. handler . clone ( ) )
322+ . map ( |h| EventHandler {
323+ handler : h. handler . clone ( ) ,
324+ receipt : h. receipt ,
325+ has_call_decls : !h. calls . raw_decls . is_empty ( ) ,
326+ } )
291327 . collect ( ) ,
292328 call_handlers : eth
293329 . mapping
@@ -299,7 +335,10 @@ fn convert_template(t: GraphUnresolvedDST<Chain>) -> Template {
299335 . mapping
300336 . block_handlers
301337 . iter ( )
302- . map ( |h| h. handler . clone ( ) )
338+ . map ( |h| BlockHandler {
339+ handler : h. handler . clone ( ) ,
340+ filter : h. filter . as_ref ( ) . map ( convert_block_handler_filter) ,
341+ } )
303342 . collect ( ) ,
304343 } ,
305344 GraphUnresolvedDST :: Offchain ( off) => Template {
@@ -339,6 +378,15 @@ fn convert_template(t: GraphUnresolvedDST<Chain>) -> Template {
339378 }
340379}
341380
381+ /// Convert a graph-node `BlockHandlerFilter` to gnd's simplified `BlockHandlerFilterKind`.
382+ fn convert_block_handler_filter ( filter : & BlockHandlerFilter ) -> BlockHandlerFilterKind {
383+ match filter {
384+ BlockHandlerFilter :: Call => BlockHandlerFilterKind :: Call ,
385+ BlockHandlerFilter :: Once => BlockHandlerFilterKind :: Once ,
386+ BlockHandlerFilter :: Polling { .. } => BlockHandlerFilterKind :: Polling ,
387+ }
388+ }
389+
342390/// Get the directory containing a manifest file.
343391///
344392/// This handles the edge case where `manifest_path` is a bare filename
0 commit comments