Skip to content

Commit

Permalink
derive path and seed file as cli args
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Apr 26, 2024
1 parent 599fd87 commit db928c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
13 changes: 5 additions & 8 deletions basecoin/src/bin/basecoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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();
Expand Down Expand Up @@ -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}");
Expand All @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions basecoin/src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub enum Commands {
Start,
#[command(subcommand)]
Query(QueryCmd),
#[command(subcommand)]
Tx(TxCmd),
}

Expand All @@ -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),
}

Expand Down

0 comments on commit db928c1

Please sign in to comment.