aboutsummaryrefslogtreecommitdiff
path: root/src/cmd.rs
blob: b64873261fbc5547f0aae65c6f4beac610b0b4ab (plain)
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
//! Module containing subcommands.

pub mod address;
pub mod new;

use crate::{account::PrivateKey, hdk, mnemonic::Mnemonic};
use anyhow::Result;
use structopt::StructOpt;

/// Shared account options.
#[derive(Debug, StructOpt)]
struct AccountOptions {
    /// The BIP-0039 mnemonic phrase for seeding the HD wallet.
    #[structopt(short, long, env)]
    mnemonic: Mnemonic,

    /// The BIP-44 account index for deriving a private from the mnemonic seed
    /// phrase.
    #[structopt(long, env, default_value = "0")]
    account_index: usize,
}

impl AccountOptions {
    /// Returns the private key for the specified account options.
    pub fn private_key(&self) -> Result<PrivateKey> {
        let path = format!("m/44'/60'/0'/0/{}", self.account_index).parse()?;
        hdk::derive(&self.mnemonic, &path)
    }
}