diff --git a/rust-lightclient/src/commands.rs b/rust-lightclient/src/commands.rs index 8979990..64707f4 100644 --- a/rust-lightclient/src/commands.rs +++ b/rust-lightclient/src/commands.rs @@ -39,6 +39,7 @@ impl Command for HelpCommand { fn exec(&self, _args: &[String], _: &mut LightClient) { // Print a list of all commands + println!("Available commands:"); get_commands().iter().for_each(| (cmd, obj) | { println!("{} - {}", cmd, obj.short_help()); }); diff --git a/rust-lightclient/src/lightclient.rs b/rust-lightclient/src/lightclient.rs index c5e61e4..584d9c9 100644 --- a/rust-lightclient/src/lightclient.rs +++ b/rust-lightclient/src/lightclient.rs @@ -1,5 +1,6 @@ use crate::lightwallet::LightWallet; +use std::path::Path; use std::fs::File; use std::io; use std::io::prelude::*; @@ -63,9 +64,20 @@ impl LightClient { } pub fn do_read(&mut self) { + if !Path::new("wallet.dat").exists() { + println!("No existing wallet"); + return; + } + print!("Reading wallet..."); io::stdout().flush().ok().expect("Could not flush stdout"); - let mut file_buffer = File::open("wallet.dat").unwrap(); + let mut file_buffer = match File::open("wallet.dat") { + Ok(f) => f, + Err(e) => { + println!("[Error: {}]", e.description()); + return; + } + }; let lw = LightWallet::read(&mut file_buffer).unwrap(); self.wallet = Arc::new(lw); diff --git a/rust-lightclient/src/main.rs b/rust-lightclient/src/main.rs index a68e0a5..a0a4139 100644 --- a/rust-lightclient/src/main.rs +++ b/rust-lightclient/src/main.rs @@ -16,6 +16,7 @@ pub mod grpc_client { pub fn main() { + println!("Starting Light Client"); let mut lightclient = LightClient::new(); // At startup, read the wallet.dat @@ -23,11 +24,12 @@ pub fn main() { // `()` can be used when no completer is required let mut rl = Editor::<()>::new(); - if rl.load_history("history.txt").is_err() { - println!("No previous history."); - } + let _ = rl.load_history("history.txt"); + + println!("Ready!"); + loop { - let readline = rl.readline(&format!("Block:{} (h for help) >> ", lightclient.last_scanned_height())); + let readline = rl.readline(&format!("Block:{} (type 'help') >> ", lightclient.last_scanned_height())); match readline { Ok(line) => { rl.add_history_entry(line.as_str());