-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathreference.rs
More file actions
54 lines (45 loc) · 1.48 KB
/
reference.rs
File metadata and controls
54 lines (45 loc) · 1.48 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
use super::ProofOfIndexingEvent;
use crate::prelude::DeploymentHash;
use crate::util::stable_hash_glue::{impl_stable_hash, AsBytes};
use std::collections::HashMap;
use web3::types::{Address, H256};
/// The PoI is the StableHash of this struct. This reference implementation is
/// mostly here just to make sure that the online implementation is
/// well-implemented (without conflicting sequence numbers, or other oddities).
/// It's just way easier to check that this works, and serves as a kind of
/// documentation as a side-benefit.
#[allow(dead_code)]
pub struct PoI<'a> {
pub causality_regions: HashMap<String, PoICausalityRegion<'a>>,
pub subgraph_id: DeploymentHash,
pub block_hash: H256,
pub indexer: Option<Address>,
}
#[allow(dead_code)]
fn h256_as_bytes(val: &H256) -> AsBytes<&[u8]> {
AsBytes(val.as_bytes())
}
#[allow(dead_code)]
fn indexer_opt_as_bytes(val: &Option<Address>) -> Option<AsBytes<&[u8]>> {
val.as_ref().map(|v| AsBytes(v.as_bytes()))
}
impl_stable_hash!(PoI<'_> {
causality_regions,
subgraph_id,
block_hash: h256_as_bytes,
indexer: indexer_opt_as_bytes
});
pub struct PoICausalityRegion<'a> {
pub blocks: Vec<Block<'a>>,
}
impl_stable_hash!(PoICausalityRegion<'_> {blocks});
impl PoICausalityRegion<'_> {
pub fn from_network(network: &str) -> String {
format!("ethereum/{}", network)
}
}
#[derive(Default)]
pub struct Block<'a> {
pub events: Vec<ProofOfIndexingEvent<'a>>,
}
impl_stable_hash!(Block<'_> {events});