1use std::{path::PathBuf, str::FromStr};
2
3use anyhow::{bail, Result};
4use clap::Args;
5
6use crate::{Network, PrivateKey};
7
8#[derive(Debug, Args, Clone)]
11#[group(required = true, multiple = false)]
12pub struct Key<N: Network> {
13 #[clap(long = "private-key")]
15 pub private_key: Option<PrivateKey<N>>,
16 #[clap(long = "private-key-file")]
18 pub private_key_file: Option<PathBuf>,
19}
20
21impl<N: Network> Key<N> {
22 pub fn try_get(self) -> Result<PrivateKey<N>> {
23 match (self.private_key, self.private_key_file) {
24 (Some(key), None) => Ok(key),
25 (None, Some(file)) => {
26 let raw = std::fs::read_to_string(file)?.trim().to_string();
27 Ok(PrivateKey::from_str(&raw)?)
28 }
29 _ => bail!("Either `private-key` or `private-key-file` must be set"),
31 }
32 }
33}