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
use std::io;
use std::path::Path;
use std::str::FromStr;

#[derive(Clone)]
pub struct GenesisBlock {
    pub block0_path: String,
    pub block0: Vec<u8>,
}

impl GenesisBlock {
    pub(crate) fn is_fund_id(&self, fund_id: i32) -> bool {
        Path::new(&self.block0_path)
            .file_stem()
            .unwrap()
            .to_str()
            .unwrap()
            == format!("fund{}", fund_id)
    }
}

impl FromStr for GenesisBlock {
    type Err = io::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Self {
            block0: std::fs::read(s).unwrap_or_default(),
            block0_path: s.to_string(),
        })
    }
}