1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use snapshot_trigger_service::config::NetworkType;
use std::io::Write;
use std::path::Path;
use std::process::Command;

pub trait CommandExt {
    fn arg_network(&mut self, network: NetworkType) -> &mut Self;
}

impl CommandExt for Command {
    fn arg_network(&mut self, network: NetworkType) -> &mut Self {
        match network {
            NetworkType::Mainnet => self.arg("--mainnet"),
            NetworkType::Testnet(magic) => self.arg("--testnet-magic").arg(magic.to_string()),
        }
    }
}

#[allow(dead_code)]
pub fn write_content<P: AsRef<Path>>(content: &str, path: P) -> Result<(), std::io::Error> {
    let mut file = std::fs::File::create(&path)?;
    file.write_all(content.as_bytes())?;
    Ok(())
}