diff --git a/Makefile b/Makefile index 2e51165..03e7de7 100644 --- a/Makefile +++ b/Makefile @@ -23,8 +23,8 @@ info: .PHONY: gui gui: - substreams gui substreams.yaml -e eth.substreams.pinax.network:443 map_clock -s 0 -t 200000 -H "X-Sf-Substreams-Parallel-Jobs: 100" --production-mode + substreams gui substreams.yaml -e eos.substreams.pinax.network:443 map_clock -s 0 -t 200000 --production-mode .PHONY: cache cache: - substreams-sink-noop eth.substreams.pinax.network:443 substreams.yaml map_clock 0: -H "X-Sf-Substreams-Parallel-Jobs: 100" + substreams-sink-noop eos.substreams.pinax.network:443 substreams.yaml map_clock 0: -H "X-Sf-Substreams-Parallel-Jobs: 100" diff --git a/README.md b/README.md index bfa8478..cf2a1e2 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,13 @@ make gui ```mermaid graph TD; + clock[map: clock]; + sf.substreams.v1.Clock[source: sf.substreams.v1.Clock] --> clock; store_clock[store: store_clock]; - sf.substreams.v1.Clock[source: sf.substreams.v1.Clock] --> store_clock; + clock --> store_clock; map_clock[map: map_clock]; map_clock:params[params] --> map_clock; - sf.substreams.v1.Clock[source: sf.substreams.v1.Clock] --> map_clock; + clock --> map_clock; store_clock -- deltas --> map_clock; ``` @@ -48,20 +50,27 @@ graph TD; ### Modules ```yaml +Name: clock +Initial block: 0 +Kind: map +Input: source: sf.substreams.v1.Clock +Output Type: proto:sf.substreams.v1.Clock +Hash: 6e1bd863b0f69efe251f9c99f5468231312e4d59 + Name: store_clock Initial block: 0 Kind: store -Input: source: sf.substreams.v1.Clock +Input: map: clock Value Type: string Update Policy: set -Hash: 2810ecc8f812533b3d7d272392793a6590d863c0 +Hash: bd42bfa2c82e8d31cdc37e08ecac1df4324a555c Name: map_clock Initial block: 0 Kind: map -Input: params: day -Input: source: sf.substreams.v1.Clock +Input: params: 1d +Input: map: clock Input: store: store_clock Output Type: proto:sf.substreams.v1.Clock -Hash: 1723a789b027af657c12fe9c37eefafd56595078 +Hash: 203f7bc4be2fc8afbf3ded28d6273856856cb1d5 ``` diff --git a/src/maps.rs b/src/maps.rs index a4603f3..a08d9bd 100644 --- a/src/maps.rs +++ b/src/maps.rs @@ -2,10 +2,19 @@ use substreams::errors::Error; use substreams::pb::substreams::Clock; use substreams::store::{DeltaString, Deltas}; +#[substreams::handlers::map] +pub fn clock(clock: Clock) -> Result { + Ok(clock) +} + #[substreams::handlers::map] pub fn map_clock(params: String, clock: Clock, store: Deltas) -> Result { + if params.is_empty() { + return Ok(clock); + } + // only emit clock based on time interval for delta in store.deltas { - if !params.is_empty() && delta.key != params { + if delta.key != params { continue; } if delta.old_value == "" { diff --git a/substreams.yaml b/substreams.yaml index 13a9bec..a3b4d7a 100644 --- a/substreams.yaml +++ b/substreams.yaml @@ -13,18 +13,25 @@ binaries: file: ./target/wasm32-unknown-unknown/release/clock.wasm modules: + - name: clock + kind: map + inputs: + - source: sf.substreams.v1.Clock + output: + type: proto:sf.substreams.v1.Clock + - name: store_clock kind: store updatePolicy: set valueType: string inputs: - - source: sf.substreams.v1.Clock + - map: clock - name: map_clock kind: map inputs: - params: string - - source: sf.substreams.v1.Clock + - map: clock - store: store_clock mode: deltas output: