Make generate_remote_keypair more generic for potential other remote-wallets (#8274)
This commit is contained in:
parent
5b4ecb01ca
commit
c350543b46
|
@ -14,10 +14,7 @@ use solana_clap_utils::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use solana_cli_config::config::{Config, CONFIG_FILE};
|
use solana_cli_config::config::{Config, CONFIG_FILE};
|
||||||
use solana_remote_wallet::{
|
use solana_remote_wallet::remote_keypair::generate_remote_keypair;
|
||||||
ledger::{generate_remote_keypair, get_ledger_from_info},
|
|
||||||
remote_wallet::RemoteWalletInfo,
|
|
||||||
};
|
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
pubkey::write_pubkey_file,
|
pubkey::write_pubkey_file,
|
||||||
signature::{
|
signature::{
|
||||||
|
@ -82,14 +79,10 @@ fn get_keypair_from_matches(
|
||||||
let mut stdin = std::io::stdin();
|
let mut stdin = std::io::stdin();
|
||||||
Ok(Box::new(read_keypair(&mut stdin)?))
|
Ok(Box::new(read_keypair(&mut stdin)?))
|
||||||
}
|
}
|
||||||
KeypairUrl::Usb(path) => {
|
KeypairUrl::Usb(path) => Ok(Box::new(generate_remote_keypair(
|
||||||
let (remote_wallet_info, mut derivation_path) = RemoteWalletInfo::parse_path(path)?;
|
path,
|
||||||
if let Some(derivation) = derivation_of(matches, "derivation_path") {
|
derivation_of(matches, "derivation_path"),
|
||||||
derivation_path = derivation;
|
)?)),
|
||||||
}
|
|
||||||
let ledger = get_ledger_from_info(remote_wallet_info)?;
|
|
||||||
Ok(Box::new(generate_remote_keypair(ledger, derivation_path)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
use crate::{
|
use crate::remote_wallet::{
|
||||||
remote_keypair::RemoteKeypair,
|
initialize_wallet_manager, DerivationPath, RemoteWallet, RemoteWalletError, RemoteWalletInfo,
|
||||||
remote_wallet::{
|
|
||||||
initialize_wallet_manager, DerivationPath, RemoteWallet, RemoteWalletError,
|
|
||||||
RemoteWalletInfo, RemoteWalletType,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use dialoguer::{theme::ColorfulTheme, Select};
|
use dialoguer::{theme::ColorfulTheme, Select};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
@ -369,13 +365,3 @@ pub fn get_ledger_from_info(
|
||||||
};
|
};
|
||||||
wallet_manager.get_ledger(&wallet_base_pubkey)
|
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -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::{
|
use solana_sdk::{
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{KeypairUtil, Signature},
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue