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
use assert_fs::TempDir;
use std::path::{Path, PathBuf};

pub struct DeploymentTree {
    root: PathBuf,
}

impl DeploymentTree {
    pub fn new<P: AsRef<Path>>(root: P) -> Self {
        Self {
            root: root.as_ref().to_path_buf(),
        }
    }

    pub fn root_path(&self) -> PathBuf {
        self.root.clone()
    }

    pub fn genesis_path(&self) -> PathBuf {
        self.root.join("genesis.yaml")
    }

    pub fn block0_path(&self) -> PathBuf {
        self.root.join("block0.bin")
    }

    pub fn qr_codes_path(&self) -> PathBuf {
        self.root.join("qr-codes")
    }

    pub fn wallet_search_pattern(&self) -> String {
        format!("{}/wallet_*_*", self.root.display())
    }

    pub fn wallet_secret<S: Into<String>>(&self, alias: S) -> PathBuf {
        self.root.join(alias.into())
    }

    pub fn voting_token(&self) -> PathBuf {
        self.root.join("voting_token.txt")
    }
}

impl From<&TempDir> for DeploymentTree {
    fn from(temp_dir: &TempDir) -> Self {
        Self::new(temp_dir.path())
    }
}