Skip to content

Commit

Permalink
add clock module
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Oct 21, 2024
1 parent 5463067 commit 874f82d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```

Expand All @@ -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
```
11 changes: 10 additions & 1 deletion src/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Clock, Error> {
Ok(clock)
}

#[substreams::handlers::map]
pub fn map_clock(params: String, clock: Clock, store: Deltas<DeltaString>) -> Result<Clock, Error> {
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 == "" {
Expand Down
11 changes: 9 additions & 2 deletions substreams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 874f82d

Please sign in to comment.