cli/commands/wallet/
address.rs

1use std::path::PathBuf;
2
3use anyhow::{Context, Result};
4use mina_node_account::AccountSecretKey;
5
6#[derive(Debug, clap::Args)]
7pub struct Address {
8    /// Path to encrypted key file
9    #[arg(long, env)]
10    pub from: PathBuf,
11
12    /// Password to decrypt the key
13    #[arg(
14        env = "MINA_PRIVKEY_PASS",
15        default_value = "",
16        help = "Password to decrypt the key (env: MINA_PRIVKEY_PASS)"
17    )]
18    pub password: String,
19}
20
21impl Address {
22    pub fn run(self) -> Result<()> {
23        // Load and decrypt the key
24        let secret_key = AccountSecretKey::from_encrypted_file(&self.from, &self.password)
25            .with_context(|| format!("Failed to decrypt key file: {}", self.from.display()))?;
26
27        // Get the public key
28        let public_key = secret_key.public_key();
29
30        // Display the address
31        println!("{}", public_key);
32
33        Ok(())
34    }
35}