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
use crate::cardano_cli::wrapper::cli::command;
use crate::cardano_cli::wrapper::Error;
use snapshot_trigger_service::config::NetworkType;
use std::io::Write;
use std::path::Path;
use std::process::ExitStatus;

pub struct Address {
    address_command: command::Address,
}

impl Address {
    pub fn new(address_command: command::Address) -> Self {
        Self { address_command }
    }

    pub fn build<P: AsRef<Path>, Q: AsRef<Path>>(
        self,
        payment_verification_key: P,
        stake_verification_key: P,
        output: Q,
        network: NetworkType,
    ) -> Result<ExitStatus, Error> {
        let output = self
            .address_command
            .build()
            .payment_verification_key_file(payment_verification_key.as_ref())
            .stake_verification_key_file(stake_verification_key.as_ref())
            .out_file(output.as_ref())
            .network(network)
            .build()
            .output()
            .map_err(|e| Error::Io(e.to_string()))?;

        std::io::stdout()
            .write_all(&output.stdout)
            .map_err(|e| Error::Io(e.to_string()))?;
        std::io::stderr()
            .write_all(&output.stderr)
            .map_err(|e| Error::Io(e.to_string()))?;

        Ok(output.status)
    }
}