Skip to content

Commit b72621e

Browse files
respect substreams datasource startBlock (#5617)
1 parent 7c499c2 commit b72621e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

chain/substreams/src/data_source.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ impl blockchain::UnresolvedDataSource<Chain> for UnresolvedDataSource {
224224
}
225225
};
226226

227+
let initial_block =
228+
initial_block.map(|x| x.max(self.source.start_block.unwrap_or_default() as u64));
229+
227230
let initial_block: Option<i32> = initial_block
228231
.map_or(Ok(None), |x: u64| TryInto::<i32>::try_into(x).map(Some))
229232
.map_err(anyhow::Error::from)?;
@@ -369,6 +372,34 @@ mod test {
369372
assert_eq!(ds, expected);
370373
}
371374

375+
#[test]
376+
fn parse_data_source_with_startblock() {
377+
let ds: UnresolvedDataSource =
378+
serde_yaml::from_str(TEMPLATE_DATA_SOURCE_WITH_START_BLOCK).unwrap();
379+
let expected = UnresolvedDataSource {
380+
kind: SUBSTREAMS_KIND.into(),
381+
network: Some("mainnet".into()),
382+
name: "Uniswap".into(),
383+
source: crate::UnresolvedSource {
384+
package: crate::UnresolvedPackage {
385+
module_name: "output".into(),
386+
file: Link {
387+
link: "/ipfs/QmbHnhUFZa6qqqRyubUYhXntox1TCBxqryaBM1iNGqVJzT".into(),
388+
},
389+
params: None,
390+
},
391+
start_block: Some(567),
392+
},
393+
mapping: UnresolvedMapping {
394+
api_version: "0.0.7".into(),
395+
kind: "substreams/graph-entities".into(),
396+
handler: None,
397+
file: None,
398+
},
399+
};
400+
assert_eq!(ds, expected);
401+
}
402+
372403
#[test]
373404
fn parse_data_source_with_params() {
374405
let ds: UnresolvedDataSource =
@@ -604,6 +635,22 @@ mod test {
604635
apiVersion: 0.0.7
605636
"#;
606637

638+
const TEMPLATE_DATA_SOURCE_WITH_START_BLOCK: &str = r#"
639+
kind: substreams
640+
name: Uniswap
641+
network: mainnet
642+
source:
643+
startBlock: 567
644+
package:
645+
moduleName: output
646+
file:
647+
/: /ipfs/QmbHnhUFZa6qqqRyubUYhXntox1TCBxqryaBM1iNGqVJzT
648+
# This IPFs path would be generated from a local path at deploy time
649+
mapping:
650+
kind: substreams/graph-entities
651+
apiVersion: 0.0.7
652+
"#;
653+
607654
const TEMPLATE_DATA_SOURCE_WITH_MAPPING: &str = r#"
608655
kind: substreams
609656
name: Uniswap

0 commit comments

Comments
 (0)