diff --git a/Cargo.lock b/Cargo.lock index 26d239bcd07b49..4702ff91c3f272 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -816,6 +816,16 @@ dependencies = [ "syn 0.15.42 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dialoguer" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "console 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "diff" version = "0.1.11" @@ -4006,6 +4016,7 @@ version = "0.24.0" dependencies = [ "bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dialoguer 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 4.0.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6122,6 +6133,7 @@ dependencies = [ "checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" "checksum derivative 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "942ca430eef7a3806595a6737bc388bf51adb888d3fc0dd1b50f1c170167ee3a" +"checksum dialoguer 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94616e25d2c04fc97253d145f6ca33ad84a584258dc70c4e621cc79a57f903b6" "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" diff --git a/keygen/Cargo.toml b/keygen/Cargo.toml index 8ac34d200e2351..e4292859faf161 100644 --- a/keygen/Cargo.toml +++ b/keygen/Cargo.toml @@ -11,6 +11,7 @@ edition = "2018" [dependencies] bs58 = "0.3.0" clap = "2.33" +dialoguer = "0.5.0" dirs = "2.0.2" num_cpus = "1.12.0" rpassword = "4.0" diff --git a/keygen/src/keygen.rs b/keygen/src/keygen.rs index 4f1df236cbea0d..a1533f3bd178b7 100644 --- a/keygen/src/keygen.rs +++ b/keygen/src/keygen.rs @@ -4,6 +4,7 @@ use clap::{ crate_description, crate_name, value_t, values_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand, }; +use dialoguer::{theme::ColorfulTheme, Select}; use num_cpus; use solana_clap_utils::{ input_parsers::{derivation_of, pubkey_of}, @@ -396,21 +397,42 @@ fn main() -> Result<(), Box> { } let wallet_base_pubkey = pubkey_of(matches, "wallet_base_pubkey").unwrap_or_else(|| { + let devices = wallet_manager.list_devices(); if device_count > 1 { - // TODO: Prompt for choice - println!("Choosing between multiple wallets currently not supported"); - exit(1); + let select_devices: Vec = devices + .iter() + .map(|device_info| { + format!( + "{}, {}, base pubkey: {:?}", + device_info.manufacturer, + device_info.name, + device_info.pubkey + ) + }) + .collect(); + + let selection = Select::with_theme(&ColorfulTheme::default()) + .with_prompt( + "Multiple hardware wallets found. Please select a device", + ) + .default(0) + .items(&select_devices[..]) + .interact() + .unwrap(); + devices[selection].pubkey + } else { + devices[0].pubkey } - wallet_manager.list_devices()[0].pubkey }); let ledger = wallet_manager.get_ledger(&wallet_base_pubkey).unwrap_or_else(|_| { println!("Wallet {:?} not found. Make sure the Solana Wallet app is still running.", wallet_base_pubkey); exit(1); }); + let wallet_info = wallet_manager.get_wallet_info(&wallet_base_pubkey).unwrap(); println!( - "Getting key from wallet: {:?}", - wallet_manager.get_wallet_info(&wallet_base_pubkey).unwrap() + "Getting key from wallet: {}, {}, {:?}", + wallet_info.manufacturer, wallet_info.name, wallet_info.pubkey ); let derivation = derivation_of(matches, "derivation")