1use crate::{utils, PendingSigner, WalletSigner};
2use clap::Parser;
3use eyre::Result;
4use serde::Serialize;
56/// A wrapper for the raw data options for `Wallet`, extracted to also be used standalone.
7/// The raw wallet options can either be:
8/// 1. Private Key (cleartext in CLI)
9/// 2. Private Key (interactively via secure prompt)
10/// 3. Mnemonic (via file path)
11#[derive(Clone, Debug, Default, Serialize, Parser)]
12#[command(next_help_heading = "Wallet options - raw", about = None, long_about = None)]
13pub struct RawWalletOpts {
14/// Open an interactive prompt to enter your private key.
15#[arg(long, short)]
16pub interactive: bool,
1718/// Use the provided private key.
19#[arg(long, value_name = "RAW_PRIVATE_KEY")]
20pub private_key: Option<String>,
2122/// Use the mnemonic phrase of mnemonic file at the specified path.
23#[arg(long, alias = "mnemonic-path")]
24pub mnemonic: Option<String>,
2526/// Use a BIP39 passphrase for the mnemonic.
27#[arg(long, value_name = "PASSPHRASE")]
28pub mnemonic_passphrase: Option<String>,
2930/// The wallet derivation path.
31 ///
32 /// Works with both --mnemonic-path and hardware wallets.
33#[arg(long = "mnemonic-derivation-path", alias = "hd-path", value_name = "PATH")]
34pub hd_path: Option<String>,
3536/// Use the private key from the given mnemonic index.
37 ///
38 /// Used with --mnemonic-path.
39#[arg(long, conflicts_with = "hd_path", default_value_t = 0, value_name = "INDEX")]
40pub mnemonic_index: u32,
41}
4243impl RawWalletOpts {
44/// Returns signer configured by provided parameters.
45pub fn signer(&self) -> Result<Option<WalletSigner>> {
46if self.interactive {
47return Ok(Some(PendingSigner::Interactive.unlock()?));
48 }
49if let Some(private_key) = &self.private_key {
50return Ok(Some(utils::create_private_key_signer(private_key)?));
51 }
52if let Some(mnemonic) = &self.mnemonic {
53return Ok(Some(utils::create_mnemonic_signer(
54mnemonic,
55self.mnemonic_passphrase.as_deref(),
56self.hd_path.as_deref(),
57self.mnemonic_index,
58 )?));
59 }
60Ok(None)
61 }
62}