Browse Source

Cleanup

checkpoints
Aditya Kulkarni 5 years ago
parent
commit
d308772965
  1. 1
      rust-lightclient/src/commands.rs
  2. 14
      rust-lightclient/src/lightclient.rs
  3. 10
      rust-lightclient/src/main.rs

1
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());
});

14
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);

10
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());

Loading…
Cancel
Save