Skip to content

Commit

Permalink
Merge branch 'main' into teach-me
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod committed Jul 7, 2024
2 parents 096f7ac + 14fc6d6 commit 76011ac
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
15 changes: 13 additions & 2 deletions src/commands/account/add_key/use_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#[interactive_clap(input_context = super::access_key_type::AccessTypeContext)]
#[interactive_clap(output_context = AddLedgerKeyActionContext)]
pub struct AddLedgerKeyAction {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
seed_phrase_hd_path: crate::types::slip10::BIP32Path,
#[interactive_clap(named_arg)]
/// Select network
network_config: crate::network_for_transaction::NetworkForTransactionArgs,
Expand All @@ -18,9 +21,9 @@ pub struct AddLedgerKeyActionContext {
impl AddLedgerKeyActionContext {
pub fn from_previous_context(
previous_context: super::access_key_type::AccessTypeContext,
_scope: &<AddLedgerKeyAction as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
scope: &<AddLedgerKeyAction as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let seed_phrase_hd_path = crate::transaction_signature_options::sign_with_ledger::SignLedger::input_seed_phrase_hd_path()?.unwrap();
let seed_phrase_hd_path = scope.seed_phrase_hd_path.clone();
eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
seed_phrase_hd_path
Expand Down Expand Up @@ -85,3 +88,11 @@ impl From<AddLedgerKeyActionContext> for crate::commands::ActionContext {
}
}
}

impl AddLedgerKeyAction {
pub fn input_seed_phrase_hd_path(
_context: &super::access_key_type::AccessTypeContext,
) -> color_eyre::eyre::Result<Option<crate::types::slip10::BIP32Path>> {
crate::transaction_signature_options::sign_with_ledger::input_seed_phrase_hd_path()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use color_eyre::eyre::Context;
#[interactive_clap(input_context = crate::GlobalContext)]
#[interactive_clap(output_context = SaveWithLedgerContext)]
pub struct SaveWithLedger {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
seed_phrase_hd_path: crate::types::slip10::BIP32Path,
#[interactive_clap(named_arg)]
/// Specify a folder to save the implicit account file
save_to_folder: super::SaveToFolder,
Expand All @@ -17,12 +20,12 @@ pub struct SaveWithLedgerContext(super::SaveImplicitAccountContext);
impl SaveWithLedgerContext {
pub fn from_previous_context(
previous_context: crate::GlobalContext,
_scope: &<SaveWithLedger as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
scope: &<SaveWithLedger as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let on_after_getting_folder_path_callback: super::OnAfterGettingFolderPathCallback =
std::sync::Arc::new({
let seed_phrase_hd_path = scope.seed_phrase_hd_path.clone();
move |folder_path| {
let seed_phrase_hd_path = crate::transaction_signature_options::sign_with_ledger::SignLedger::input_seed_phrase_hd_path()?.unwrap();
eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
seed_phrase_hd_path
Expand Down Expand Up @@ -72,3 +75,11 @@ impl From<SaveWithLedgerContext> for super::SaveImplicitAccountContext {
item.0
}
}

impl SaveWithLedger {
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_ledger::input_seed_phrase_hd_path()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#[interactive_clap(input_context = super::super::NewAccountContext)]
#[interactive_clap(output_context = AddAccessWithLedgerContext)]
pub struct AddAccessWithLedger {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
seed_phrase_hd_path: crate::types::slip10::BIP32Path,
#[interactive_clap(named_arg)]
/// What is the signer account ID?
sign_as: super::super::sign_as::SignerAccountId,
Expand All @@ -13,9 +16,9 @@ pub struct AddAccessWithLedgerContext(super::super::AccountPropertiesContext);
impl AddAccessWithLedgerContext {
pub fn from_previous_context(
previous_context: super::super::NewAccountContext,
_scope: &<AddAccessWithLedger as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
scope: &<AddAccessWithLedger as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let seed_phrase_hd_path = crate::transaction_signature_options::sign_with_ledger::SignLedger::input_seed_phrase_hd_path()?.unwrap();
let seed_phrase_hd_path = scope.seed_phrase_hd_path.clone();
eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
seed_phrase_hd_path
Expand Down Expand Up @@ -53,3 +56,11 @@ impl From<AddAccessWithLedgerContext> for super::super::AccountPropertiesContext
item.0
}
}

impl AddAccessWithLedger {
pub fn input_seed_phrase_hd_path(
_context: &super::super::NewAccountContext,
) -> color_eyre::eyre::Result<Option<crate::types::slip10::BIP32Path>> {
crate::transaction_signature_options::sign_with_ledger::input_seed_phrase_hd_path()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#[interactive_clap(input_context = super::super::NewAccountContext)]
#[interactive_clap(output_context = AddAccessWithLedgerContext)]
pub struct AddAccessWithLedger {
#[interactive_clap(long)]
#[interactive_clap(skip_default_input_arg)]
seed_phrase_hd_path: crate::types::slip10::BIP32Path,
#[interactive_clap(named_arg)]
/// Select network
network_config: super::super::network::Network,
Expand All @@ -13,9 +16,9 @@ pub struct AddAccessWithLedgerContext(super::super::SponsorServiceContext);
impl AddAccessWithLedgerContext {
pub fn from_previous_context(
previous_context: super::super::NewAccountContext,
_scope: &<AddAccessWithLedger as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
scope: &<AddAccessWithLedger as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let seed_phrase_hd_path = crate::transaction_signature_options::sign_with_ledger::SignLedger::input_seed_phrase_hd_path()?.unwrap();
let seed_phrase_hd_path = scope.seed_phrase_hd_path.clone();
eprintln!(
"Please allow getting the PublicKey on Ledger device (HD Path: {})",
seed_phrase_hd_path
Expand Down Expand Up @@ -50,3 +53,11 @@ impl From<AddAccessWithLedgerContext> for super::super::SponsorServiceContext {
item.0
}
}

impl AddAccessWithLedger {
pub fn input_seed_phrase_hd_path(
_context: &super::super::NewAccountContext,
) -> color_eyre::eyre::Result<Option<crate::types::slip10::BIP32Path>> {
crate::transaction_signature_options::sign_with_ledger::input_seed_phrase_hd_path()
}
}
18 changes: 12 additions & 6 deletions src/transaction_signature_options/sign_with_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl interactive_clap::FromCli for SignLedger {
let mut clap_variant = optional_clap_variant.unwrap_or_default();

if clap_variant.seed_phrase_hd_path.is_none() {
clap_variant.seed_phrase_hd_path = match Self::input_seed_phrase_hd_path() {
clap_variant.seed_phrase_hd_path = match Self::input_seed_phrase_hd_path(&context) {
Ok(Some(seed_phrase_hd_path)) => Some(seed_phrase_hd_path),
Ok(None) => return interactive_clap::ResultFromCli::Cancel(Some(clap_variant)),
Err(err) => return interactive_clap::ResultFromCli::Err(Some(clap_variant), err),
Expand Down Expand Up @@ -245,12 +245,9 @@ impl interactive_clap::FromCli for SignLedger {

impl SignLedger {
pub 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 you not sure leave blank for default):")
.with_starting_input("44'/397'/0'/0'/1'")
.prompt()?,
))
input_seed_phrase_hd_path()
}

fn input_nonce(
Expand Down Expand Up @@ -278,3 +275,12 @@ impl SignLedger {
Ok(None)
}
}

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 you not sure leave blank for default):")
.with_starting_input("44'/397'/0'/0'/1'")
.prompt()?,
))
}

0 comments on commit 76011ac

Please sign in to comment.