Skip to content

Commit

Permalink
add block_min
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Jul 5, 2024
1 parent dfc588b commit 5ec2a32
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clock"
version = "0.1.0"
version = "0.2.0"
authors = ["Denis <denis@pinax.network>", "Etienne <etienne@pinax.network>"]
description = "Block ID, number & timestamp"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ info:

.PHONY: run
run:
substreams run -e eth.substreams.pinax.network:9000 graph_out -s -1
substreams run -e eth.substreams.pinax.network:443 graph_out -s -100

.PHONY: gui
gui:
substreams gui -e eth.substreams.pinax.network:9000 graph_out -s -1
substreams gui -e eth.substreams.pinax.network:443 graph_out -s 1000 -t 1001

.PHONY: deploy
deploy:
Expand Down
14 changes: 14 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use substreams::errors::Error;
use substreams::pb::substreams::store_delta::Operation;
use substreams::pb::sf::substreams::index::v1::Keys;
use substreams::store::{DeltaInt64, Deltas};

#[substreams::handlers::map]
fn block_index(min_block: Deltas<DeltaInt64>) -> Result<Keys, Error> {
Ok(match min_block.deltas[0].operation != Operation::Create {
true => Keys::default(),
false => Keys {
keys: vec!["clock".to_string()],
},
})
}
22 changes: 3 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
use substreams::errors::Error;
use substreams::pb::substreams::Clock;
use substreams_entity_change::pb::entity::EntityChanges;
use substreams_entity_change::tables::Tables;

#[substreams::handlers::map]
pub fn graph_out(clock: Clock) -> Result<EntityChanges, Error> {
let mut tables = Tables::new();
let timestamp = clock.timestamp.unwrap();

tables
.create_row("Clock", &clock.id)
.set_bigint("number", &clock.number.to_string())
.set_bigint("seconds", &timestamp.seconds.to_string())
.set_bigint("nanos", &timestamp.nanos.to_string())
.set("timestamp", timestamp.to_string());

Ok(tables.to_entity_changes())
}
mod sinks;
mod index;
mod stores;
21 changes: 21 additions & 0 deletions src/sinks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use substreams::errors::Error;
use substreams::pb::substreams::Clock;
use substreams_entity_change::pb::entity::EntityChanges;
use substreams_entity_change::tables::Tables;

#[substreams::handlers::map]
pub fn graph_out(clock: Clock) -> Result<EntityChanges, Error> {
let mut tables = Tables::new();
let timestamp = clock.timestamp.unwrap();
let day = timestamp.seconds / 86400;

tables
.create_row("Clock", &clock.id)
.set_bigint("day", &day.to_string())
.set_bigint("number", &clock.number.to_string())
.set_bigint("seconds", &timestamp.seconds.to_string())
.set_bigint("nanos", &timestamp.nanos.to_string())
.set("timestamp", timestamp.to_string());

Ok(tables.to_entity_changes())
}
8 changes: 8 additions & 0 deletions src/stores.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use substreams::pb::substreams::Clock;
use substreams::store::{StoreMin, StoreMinInt64, StoreNew};

#[substreams::handlers::store]
pub fn store_min_block(clock: Clock, store: StoreMinInt64) {
let day = clock.timestamp.unwrap().seconds / 86400;
store.min(0, day.to_string(), clock.number as i64);
}
26 changes: 23 additions & 3 deletions substreams.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
specVersion: v0.1.0
package:
name: clock
version: v0.1.0
url: https://github.com/pinax-network/subgraphs
version: v0.2.0
url: https://github.com/pinax-network/substreams-clock
doc: Block ID, number & timestamp

imports:
entities: https://github.com/streamingfast/substreams-sink-entity-changes/releases/download/v1.3.0/substreams-sink-entity-changes-v1.3.0.spkg
entities: https://github.com/streamingfast/substreams-sink-entity-changes/releases/download/v1.3.2/substreams-sink-entity-changes-v1.3.2.spkg

binaries:
default:
type: wasm/rust-v1
file: ./target/wasm32-unknown-unknown/release/clock.wasm

modules:
- name: store_min_block
kind: store
updatePolicy: min
valueType: int64
inputs:
- source: sf.substreams.v1.Clock

- name: block_index
kind: blockIndex
inputs:
- store: store_min_block
mode: deltas
output:
type: proto:sf.substreams.index.v1.Keys

- name: graph_out
kind: map
inputs:
- source: sf.substreams.v1.Clock
blockFilter:
module: block_index
query:
string: clock
params: false
output:
type: proto:sf.substreams.sink.entity.v1.EntityChanges

0 comments on commit 5ec2a32

Please sign in to comment.