Make generate_remote_keypair more generic for potential other remote-wallets (#8274) (#8275)

automerge
This commit is contained in:
mergify[bot]
2020-02-14 09:37:39 -08:00
committed by GitHub
parent 79e340c499
commit 51a8d0356f
3 changed files with 32 additions and 29 deletions

View File

@@ -1,9 +1,5 @@
use crate::{
remote_keypair::RemoteKeypair,
remote_wallet::{
initialize_wallet_manager, DerivationPath, RemoteWallet, RemoteWalletError,
RemoteWalletInfo, RemoteWalletType,
},
use crate::remote_wallet::{
initialize_wallet_manager, DerivationPath, RemoteWallet, RemoteWalletError, RemoteWalletInfo,
};
use dialoguer::{theme::ColorfulTheme, Select};
use log::*;
@@ -369,13 +365,3 @@ pub fn get_ledger_from_info(
};
wallet_manager.get_ledger(&wallet_base_pubkey)
}
pub fn generate_remote_keypair(
ledger: Arc<LedgerWallet>,
derivation_path: DerivationPath,
) -> RemoteKeypair {
RemoteKeypair {
wallet_type: RemoteWalletType::Ledger(ledger),
derivation_path,
}
}

View File

@@ -1,4 +1,9 @@
use crate::remote_wallet::{DerivationPath, RemoteWallet, RemoteWalletType};
use crate::{
ledger::get_ledger_from_info,
remote_wallet::{
DerivationPath, RemoteWallet, RemoteWalletError, RemoteWalletInfo, RemoteWalletType,
},
};
use solana_sdk::{
pubkey::Pubkey,
signature::{KeypairUtil, Signature},
@@ -36,3 +41,22 @@ impl KeypairUtil for RemoteKeypair {
}
}
}
pub fn generate_remote_keypair(
path: String,
explicit_derivation_path: Option<DerivationPath>,
) -> Result<RemoteKeypair, RemoteWalletError> {
let (remote_wallet_info, mut derivation_path) = RemoteWalletInfo::parse_path(path)?;
if let Some(derivation) = explicit_derivation_path {
derivation_path = derivation;
}
if remote_wallet_info.manufacturer == "ledger" {
let ledger = get_ledger_from_info(remote_wallet_info)?;
Ok(RemoteKeypair {
wallet_type: RemoteWalletType::Ledger(ledger),
derivation_path,
})
} else {
Err(RemoteWalletError::DeviceTypeMismatch)
}
}