-
Notifications
You must be signed in to change notification settings - Fork 1
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
7f50988
commit 0c8276d
Showing
13 changed files
with
115 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ dev/ | |
buf.gen.yaml | ||
*.db | ||
data/ | ||
state.yaml | ||
|
||
### Substreams template | ||
.envrc | ||
|
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
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,4 +1,4 @@ | ||
[toolchain] | ||
channel = "1.65.0" | ||
components = [ "rustfmt" ] | ||
targets = [ "wasm32-unknown-unknown" ] | ||
channel = "1.76.0" | ||
components = ["rustfmt"] | ||
targets = ["wasm32-unknown-unknown"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 +1,2 @@ | ||
mod maps; | ||
mod index; | ||
mod stores; | ||
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 |
---|---|---|
@@ -1,7 +1,19 @@ | ||
use substreams::errors::Error; | ||
use substreams::pb::substreams::Clock; | ||
use substreams::store::{DeltaString, Deltas}; | ||
|
||
#[substreams::handlers::map] | ||
pub fn map_clock(clock: Clock) -> Result<Clock, Error> { | ||
Ok(clock) | ||
} | ||
pub fn map_clock(params: String, clock: Clock, store: Deltas<DeltaString>) -> Result<Clock, Error> { | ||
for delta in store.deltas { | ||
if !params.is_empty() && delta.key != params { | ||
continue; | ||
} | ||
if delta.old_value == "" { | ||
continue; // skips genesis block | ||
} | ||
if delta.old_value != delta.new_value { | ||
return Ok(clock); | ||
} | ||
} | ||
Ok(Clock::default()) // empty clock, block will be skipped | ||
} |
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,8 +1,49 @@ | ||
use substreams::pb::substreams::Clock; | ||
use substreams::store::{StoreMin, StoreMinInt64, StoreNew}; | ||
use substreams::store::{StoreNew, StoreSet, StoreSetString}; | ||
|
||
#[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); | ||
} | ||
pub fn store_clock(clock: Clock, store: StoreSetString) { | ||
if clock.number == 0 { | ||
return; | ||
} | ||
let timestamp = clock.timestamp.as_ref().expect("missing timestamp"); | ||
let block_date = to_date(&clock); | ||
let hour = timestamp.seconds / 3600; | ||
store.set(0, "hour", &hour.to_string()); | ||
store.set(0, "day", &block_date); | ||
store.set(0, "month", &to_month(&block_date)); | ||
store.set(0, "year", &to_year(&block_date)); | ||
} | ||
|
||
// Clock to date string | ||
// ex: Clock => 2015-07-30 | ||
pub fn to_date(clock: &Clock) -> String { | ||
let timestamp = clock.timestamp.as_ref().expect("missing timestamp"); | ||
timestamp | ||
.to_string() | ||
.split('T') | ||
.next() | ||
.expect("missing date") | ||
.to_string() | ||
} | ||
|
||
// Timestamp to date conversion | ||
// ex: 2015-07-30 => 2015-07 | ||
pub fn to_month(block_date: &str) -> String { | ||
match block_date | ||
.split('-') | ||
.take(2) | ||
.collect::<Vec<&str>>() | ||
.join("-") | ||
.as_str() | ||
{ | ||
date => date.to_string(), | ||
} | ||
} | ||
|
||
pub fn to_year(block_date: &str) -> String { | ||
match block_date.split('-').next() { | ||
Some(date) => date.to_string(), | ||
None => "".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