-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showcasing direct entity output from mapper
- Loading branch information
Showing
11 changed files
with
135 additions
and
392 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 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,86 +1,30 @@ | ||
mod block_timestamp; | ||
#[path = "db_out.rs"] | ||
mod db; | ||
#[path = "graph_out.rs"] | ||
mod graph; | ||
#[path = "kv_out.rs"] | ||
mod kv; | ||
mod pb; | ||
mod schema; | ||
|
||
use block_timestamp::BlockTimestamp; | ||
use pb::eth::block_meta::v1::BlockMeta; | ||
use substreams::errors::Error; | ||
use substreams::store::{DeltaProto, StoreSetIfNotExistsProto, StoreSetProto}; | ||
use substreams::{prelude::*, store}; | ||
use substreams::Hex; | ||
use substreams_database_change::pb::database::DatabaseChanges; | ||
use substreams_entity_change::pb::entity::EntityChanges; | ||
use substreams_ethereum::pb::eth::v2::{self as eth}; | ||
use substreams_sink_kv::pb::sf::substreams::sink::kv::v1::KvOperations; | ||
|
||
#[substreams::handlers::store] | ||
fn store_block_meta_start(blk: eth::Block, s: StoreSetIfNotExistsProto<BlockMeta>) { | ||
let (timestamp, meta) = block_to_block_meta(blk); | ||
|
||
s.set_if_not_exists(meta.number, timestamp.start_of_day_key(), &meta); | ||
s.set_if_not_exists(meta.number, timestamp.start_of_month_key(), &meta); | ||
} | ||
|
||
#[substreams::handlers::store] | ||
fn store_block_meta_end(blk: eth::Block, s: StoreSetProto<BlockMeta>) { | ||
let (timestamp, meta) = block_to_block_meta(blk); | ||
|
||
s.set(meta.number, timestamp.end_of_day_key(), &meta); | ||
s.set(meta.number, timestamp.end_of_month_key(), &meta); | ||
} | ||
use substreams_database_change::tables::Tables; | ||
use substreams_ethereum::pb::eth::v2::Block; | ||
|
||
#[substreams::handlers::map] | ||
pub fn db_out( | ||
block_meta_start: store::Deltas<DeltaProto<BlockMeta>>, | ||
block_meta_end: store::Deltas<DeltaProto<BlockMeta>>, | ||
) -> Result<DatabaseChanges, Error> { | ||
let mut tables = substreams_database_change::tables::Tables::new(); | ||
db::block_meta_to_database_changes(&mut tables, block_meta_start); | ||
db::block_meta_to_database_changes(&mut tables, block_meta_end); | ||
pub fn db_out(blk: Block) -> Result<DatabaseChanges, Error> { | ||
let mut tables = Tables::new(); | ||
add_block_entity(&mut tables, blk); | ||
|
||
Ok(tables.to_database_changes()) | ||
} | ||
|
||
#[substreams::handlers::map] | ||
pub fn kv_out( | ||
block_meta_start: store::Deltas<DeltaProto<BlockMeta>>, | ||
block_meta_end: store::Deltas<DeltaProto<BlockMeta>>, | ||
) -> Result<KvOperations, Error> { | ||
let mut kv_ops: KvOperations = Default::default(); | ||
kv::block_meta_to_kv_ops(&mut kv_ops, block_meta_start); | ||
kv::block_meta_to_kv_ops(&mut kv_ops, block_meta_end); | ||
|
||
Ok(kv_ops) | ||
} | ||
|
||
#[substreams::handlers::map] | ||
pub fn graph_out( | ||
block_meta_start: store::Deltas<DeltaProto<BlockMeta>>, | ||
block_meta_end: store::Deltas<DeltaProto<BlockMeta>>, | ||
) -> Result<EntityChanges, Error> { | ||
let mut tables = substreams_entity_change::tables::Tables::new(); | ||
graph::block_meta_to_entities_changes(&mut tables, block_meta_start); | ||
graph::block_meta_to_entities_changes(&mut tables, block_meta_end); | ||
|
||
Ok(tables.to_entity_changes()) | ||
} | ||
|
||
fn block_to_block_meta(blk: eth::Block) -> (BlockTimestamp, BlockMeta) { | ||
let timestamp = BlockTimestamp::from_block(&blk); | ||
let header = blk.header.unwrap(); | ||
|
||
( | ||
timestamp, | ||
BlockMeta { | ||
number: blk.number, | ||
hash: blk.hash, | ||
parent_hash: header.parent_hash, | ||
timestamp: Some(header.timestamp.unwrap()), | ||
}, | ||
) | ||
fn add_block_entity(tables: &mut Tables, blk: Block) { | ||
let block_hash = Hex(&blk.hash).to_string(); | ||
|
||
tables | ||
.create_row("block_meta", &block_hash) | ||
.set("number", blk.number) | ||
.set("hash", &block_hash) | ||
.set( | ||
"parent_hash", | ||
Hex(&blk.header.as_ref().unwrap().parent_hash).to_string(), | ||
) | ||
.set( | ||
"timestamp", | ||
blk.header.as_ref().unwrap().timestamp.as_ref().unwrap(), | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
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