From db928c1d35d8fa923a753058428fe53ed9687f4b Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Fri, 26 Apr 2024 11:40:09 +0200 Subject: [PATCH] derive path and seed file as cli args --- basecoin/src/bin/basecoin.rs | 13 +++++-------- basecoin/src/cli/command.rs | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/basecoin/src/bin/basecoin.rs b/basecoin/src/bin/basecoin.rs index e2651a1d..5496cc94 100644 --- a/basecoin/src/bin/basecoin.rs +++ b/basecoin/src/bin/basecoin.rs @@ -6,7 +6,7 @@ use std::io::Write; use std::str::FromStr; -use basecoin::cli::command::{BasecoinCli, Commands, QueryCmd, RecoverCmd, TxCmd, UpgradeCmd}; +use basecoin::cli::command::{BasecoinCli, Commands, QueryCmd, RecoverCmd, TxCmds, UpgradeCmd}; use basecoin::config::load_config; use basecoin::default_app_runner; use basecoin::helper::{dummy_chain_id, dummy_fee}; @@ -21,9 +21,6 @@ use ibc::core::host::types::identifiers::ClientId; use ibc::primitives::{Signer, ToProto}; use tracing::metadata::LevelFilter; -const SEED_FILE_PATH: &str = "./ci/user_seed.json"; -const DEFAULT_DERIVATION_PATH: &str = "m/44'/118'/0'/0/0"; - #[tokio::main] async fn main() { let cli = BasecoinCli::parse(); @@ -53,9 +50,9 @@ async fn main() { let _ = write!(std::io::stdout(), "{:#?}", query_res); } Commands::Tx(c) => { - let hdpath = StandardHDPath::from_str(DEFAULT_DERIVATION_PATH).unwrap(); + let hdpath = StandardHDPath::from_str(&c.derivation_path).unwrap(); - let key_pair = match KeyPair::from_seed_file(SEED_FILE_PATH, &hdpath) { + let key_pair = match KeyPair::from_seed_file(&c.seed_file, &hdpath) { Ok(key_pair) => key_pair, Err(e) => { tracing::error!("{e}"); @@ -65,8 +62,8 @@ async fn main() { let signer = Signer::from(key_pair.account.clone()); - let msg = match c { - TxCmd::Recover(cmd) => { + let msg = match &c.command { + TxCmds::Recover(cmd) => { let RecoverCmd { subject_client_id, substitute_client_id, diff --git a/basecoin/src/cli/command.rs b/basecoin/src/cli/command.rs index fdce95b4..acd38ca7 100644 --- a/basecoin/src/cli/command.rs +++ b/basecoin/src/cli/command.rs @@ -32,7 +32,6 @@ pub enum Commands { Start, #[command(subcommand)] Query(QueryCmd), - #[command(subcommand)] Tx(TxCmd), } @@ -51,7 +50,21 @@ pub enum UpgradeCmd { #[derive(Clone, Debug, Parser)] #[command(about = "Send a transaction to be processed by Basecoin")] -pub enum TxCmd { +pub struct TxCmd { + #[command(subcommand)] + pub command: TxCmds, + + /// The path to the file containing the seed phrase. + #[arg(long, default_value = "./ci/user_seed.json")] + pub seed_file: PathBuf, + + /// The derivation path for the key pair. + #[arg(long, default_value = "m/44'/118'/0'/0/0")] + pub derivation_path: String, +} + +#[derive(Clone, Debug, Parser)] +pub enum TxCmds { Recover(RecoverCmd), }