-
Notifications
You must be signed in to change notification settings - Fork 3
/
graph_out.rs
41 lines (36 loc) · 1.4 KB
/
graph_out.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use substreams::store::{DeltaProto, Deltas};
use substreams_entity_change::tables::Tables;
use crate::{block_timestamp::BlockTimestamp, pb::eth::block_meta::v1::BlockMeta};
pub fn add_block_meta_to_tables(tables: &mut Tables, deltas: Deltas<DeltaProto<BlockMeta>>) {
use substreams::pb::substreams::store_delta::Operation;
for delta in deltas.into_iter() {
match delta.operation {
Operation::Create => push_create(
tables,
&delta.key,
BlockTimestamp::from_key(&delta.key),
delta.new_value,
),
Operation::Update => push_update(tables, &delta.key, delta.new_value),
Operation::Delete => todo!(),
x => panic!("unsupported opeation {:?}", x),
}
}
}
fn push_create(tables: &mut Tables, key: &str, timestamp: BlockTimestamp, value: BlockMeta) {
tables
.create_row("BlockMeta", key)
.set("at", timestamp)
.set("number", value.number)
.set("hash", value.hash)
.set("parent_hash", value.parent_hash)
.set("timestamp", value.timestamp.unwrap());
}
fn push_update(tables: &mut Tables, key: &str, value: BlockMeta) {
tables
.update_row("BlockMeta", key)
.set("number", value.number)
.set("hash", value.hash)
.set("parent_hash", value.parent_hash)
.set("timestamp", value.timestamp.unwrap());
}