foundry_wallets/
raw_wallet.rs1use crate::{PendingSigner, WalletSigner, utils};
2use clap::Parser;
3use eyre::Result;
4use serde::Serialize;
5
6#[derive(Clone, Debug, Default, Serialize, Parser)]
12#[command(next_help_heading = "Wallet options - raw", about = None, long_about = None)]
13pub struct RawWalletOpts {
14 #[arg(long, short)]
16 pub interactive: bool,
17
18 #[arg(long, value_name = "RAW_PRIVATE_KEY")]
20 pub private_key: Option<String>,
21
22 #[arg(long, alias = "mnemonic-path")]
24 pub mnemonic: Option<String>,
25
26 #[arg(long, value_name = "PASSPHRASE")]
28 pub mnemonic_passphrase: Option<String>,
29
30 #[arg(long = "mnemonic-derivation-path", alias = "hd-path", value_name = "PATH")]
34 pub hd_path: Option<String>,
35
36 #[arg(long, conflicts_with = "hd_path", default_value_t = 0, value_name = "INDEX")]
40 pub mnemonic_index: u32,
41}
42
43impl RawWalletOpts {
44 pub fn signer(&self) -> Result<Option<WalletSigner>> {
46 if self.interactive {
47 return Ok(Some(PendingSigner::Interactive.unlock()?));
48 }
49 if let Some(private_key) = &self.private_key {
50 return Ok(Some(utils::create_private_key_signer(private_key)?));
51 }
52 if let Some(mnemonic) = &self.mnemonic {
53 return Ok(Some(utils::create_mnemonic_signer(
54 mnemonic,
55 self.mnemonic_passphrase.as_deref(),
56 self.hd_path.as_deref(),
57 self.mnemonic_index,
58 )?));
59 }
60 Ok(None)
61 }
62}