Skip to content

Commit

Permalink
refactored PublicKeyFromSeedPhrase
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod committed Jan 17, 2025
1 parent 2c74d26 commit e8d49d1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -74,10 +73,6 @@ impl SaveWithSeedPhrase {
pub fn input_seed_phrase_hd_path(
_context: &crate::GlobalContext,
) -> color_eyre::eyre::Result<Option<crate::types::slip10::BIP32Path>> {
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()
}
}
1 change: 1 addition & 0 deletions src/commands/account/get_public_key/from_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
16 changes: 12 additions & 4 deletions src/commands/account/get_public_key/from_seed_phrase/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -16,13 +17,20 @@ impl PublicKeyFromSeedPhraseContext {
_previous_context: crate::GlobalContext,
scope: &<PublicKeyFromSeedPhrase as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
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);

Ok(Self)
}
}

impl PublicKeyFromSeedPhrase {
pub fn input_seed_phrase_hd_path(
_context: &crate::GlobalContext,
) -> color_eyre::eyre::Result<Option<crate::types::slip10::BIP32Path>> {
crate::transaction_signature_options::sign_with_seed_phrase::input_seed_phrase_hd_path()
}
}
8 changes: 1 addition & 7 deletions src/commands/account/import_account/using_seed_phrase/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use inquire::CustomType;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = crate::GlobalContext)]
#[interactive_clap(output_context = LoginFromSeedPhraseContext)]
Expand Down Expand Up @@ -63,10 +61,6 @@ impl LoginFromSeedPhrase {
pub fn input_seed_phrase_hd_path(
_context: &crate::GlobalContext,
) -> color_eyre::eyre::Result<Option<crate::types::slip10::BIP32Path>> {
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()
}
}
15 changes: 10 additions & 5 deletions src/transaction_signature_options/sign_with_seed_phrase/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,15 @@ impl SignSeedPhrase {
fn input_seed_phrase_hd_path(
_context: &crate::commands::TransactionContext,
) -> color_eyre::eyre::Result<Option<crate::types::slip10::BIP32Path>> {
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<Option<crate::types::slip10::BIP32Path>> {
Ok(Some(
CustomType::new("Enter seed phrase HD Path (if not sure, keep the default):")
.with_starting_input("m/44'/397'/0'")
.prompt()?,
))
}

0 comments on commit e8d49d1

Please sign in to comment.