From e8d49d1150f9aebb315b2379b6ef58f98fc93d1a Mon Sep 17 00:00:00 2001 From: FroVolod Date: Fri, 17 Jan 2025 18:45:44 +0200 Subject: [PATCH] refactored PublicKeyFromSeedPhrase --- .../create_implicit_account/use_seed_phrase.rs | 7 +------ .../account/get_public_key/from_ledger/mod.rs | 1 + .../get_public_key/from_seed_phrase/mod.rs | 16 ++++++++++++---- .../import_account/using_seed_phrase/mod.rs | 8 +------- .../sign_with_seed_phrase/mod.rs | 15 ++++++++++----- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/commands/account/create_account/create_implicit_account/use_seed_phrase.rs b/src/commands/account/create_account/create_implicit_account/use_seed_phrase.rs index 2c69d0fb2..29a270e16 100644 --- a/src/commands/account/create_account/create_implicit_account/use_seed_phrase.rs +++ b/src/commands/account/create_account/create_implicit_account/use_seed_phrase.rs @@ -1,7 +1,6 @@ use std::io::Write; use color_eyre::eyre::Context; -use inquire::CustomType; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] @@ -74,10 +73,6 @@ impl SaveWithSeedPhrase { pub fn input_seed_phrase_hd_path( _context: &crate::GlobalContext, ) -> color_eyre::eyre::Result> { - Ok(Some( - CustomType::new("Enter seed phrase HD Path (if you not sure leave blank for default):") - .with_starting_input("m/44'/397'/0'") - .prompt()?, - )) + crate::transaction_signature_options::sign_with_seed_phrase::input_seed_phrase_hd_path() } } diff --git a/src/commands/account/get_public_key/from_ledger/mod.rs b/src/commands/account/get_public_key/from_ledger/mod.rs index 28e57d77c..4667468a8 100644 --- a/src/commands/account/get_public_key/from_ledger/mod.rs +++ b/src/commands/account/get_public_key/from_ledger/mod.rs @@ -2,6 +2,7 @@ #[interactive_clap(input_context = crate::GlobalContext)] #[interactive_clap(output_context = PublicKeyFromLedgerContext)] pub struct PublicKeyFromLedger { + #[interactive_clap(long)] #[interactive_clap(skip_default_input_arg)] seed_phrase_hd_path: crate::types::slip10::BIP32Path, } diff --git a/src/commands/account/get_public_key/from_seed_phrase/mod.rs b/src/commands/account/get_public_key/from_seed_phrase/mod.rs index 18a54a035..5549d7714 100644 --- a/src/commands/account/get_public_key/from_seed_phrase/mod.rs +++ b/src/commands/account/get_public_key/from_seed_phrase/mod.rs @@ -1,11 +1,12 @@ -use std::str::FromStr; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] #[interactive_clap(output_context = PublicKeyFromSeedPhraseContext)] pub struct PublicKeyFromSeedPhrase { /// Enter the seed-phrase: master_seed_phrase: String, + #[interactive_clap(long)] + #[interactive_clap(skip_default_input_arg)] + seed_phrase_hd_path: crate::types::slip10::BIP32Path, } #[derive(Debug, Clone)] @@ -16,9 +17,8 @@ impl PublicKeyFromSeedPhraseContext { _previous_context: crate::GlobalContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let seed_phrase_hd_path_default = slipped10::BIP32Path::from_str("m/44'/397'/0'").unwrap(); let public_key = crate::common::get_public_key_from_seed_phrase( - seed_phrase_hd_path_default, + scope.seed_phrase_hd_path.clone().into(), &scope.master_seed_phrase, )?; eprintln!("\nPublic key: {}", public_key); @@ -26,3 +26,11 @@ impl PublicKeyFromSeedPhraseContext { Ok(Self) } } + +impl PublicKeyFromSeedPhrase { + pub fn input_seed_phrase_hd_path( + _context: &crate::GlobalContext, + ) -> color_eyre::eyre::Result> { + crate::transaction_signature_options::sign_with_seed_phrase::input_seed_phrase_hd_path() + } +} diff --git a/src/commands/account/import_account/using_seed_phrase/mod.rs b/src/commands/account/import_account/using_seed_phrase/mod.rs index e9be35684..b1518c824 100644 --- a/src/commands/account/import_account/using_seed_phrase/mod.rs +++ b/src/commands/account/import_account/using_seed_phrase/mod.rs @@ -1,5 +1,3 @@ -use inquire::CustomType; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] #[interactive_clap(output_context = LoginFromSeedPhraseContext)] @@ -63,10 +61,6 @@ impl LoginFromSeedPhrase { pub fn input_seed_phrase_hd_path( _context: &crate::GlobalContext, ) -> color_eyre::eyre::Result> { - Ok(Some( - CustomType::new("Enter seed phrase HD Path (if you not sure leave blank for default):") - .with_starting_input("m/44'/397'/0'") - .prompt()?, - )) + crate::transaction_signature_options::sign_with_seed_phrase::input_seed_phrase_hd_path() } } diff --git a/src/transaction_signature_options/sign_with_seed_phrase/mod.rs b/src/transaction_signature_options/sign_with_seed_phrase/mod.rs index 7f6e59453..e5a820f45 100644 --- a/src/transaction_signature_options/sign_with_seed_phrase/mod.rs +++ b/src/transaction_signature_options/sign_with_seed_phrase/mod.rs @@ -213,10 +213,15 @@ impl SignSeedPhrase { fn input_seed_phrase_hd_path( _context: &crate::commands::TransactionContext, ) -> color_eyre::eyre::Result> { - Ok(Some( - CustomType::new("Enter seed phrase HD Path (if not sure, keep the default):") - .with_starting_input("m/44'/397'/0'") - .prompt()?, - )) + input_seed_phrase_hd_path() } } + +pub fn input_seed_phrase_hd_path( +) -> color_eyre::eyre::Result> { + Ok(Some( + CustomType::new("Enter seed phrase HD Path (if not sure, keep the default):") + .with_starting_input("m/44'/397'/0'") + .prompt()?, + )) +}