-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfc588b
commit 5ec2a32
Showing
7 changed files
with
72 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()], | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ×tamp.seconds.to_string()) | ||
.set_bigint("nanos", ×tamp.nanos.to_string()) | ||
.set("timestamp", timestamp.to_string()); | ||
|
||
Ok(tables.to_entity_changes()) | ||
} | ||
mod sinks; | ||
mod index; | ||
mod stores; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ×tamp.seconds.to_string()) | ||
.set_bigint("nanos", ×tamp.nanos.to_string()) | ||
.set("timestamp", timestamp.to_string()); | ||
|
||
Ok(tables.to_entity_changes()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |