Automatically load and save wallet

This commit is contained in:
Aditya Kulkarni
2019-09-06 14:09:12 -07:00
parent c2e26fbbca
commit 48d305c406
4 changed files with 59 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
use crate::lightwallet::LightWallet;
use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::sync::Arc;
@@ -62,16 +63,22 @@ impl LightClient {
}
pub fn do_read(&mut self) {
print!("Reading wallet...");
io::stdout().flush().ok().expect("Could not flush stdout");
let mut file_buffer = File::open("wallet.dat").unwrap();
let lw = LightWallet::read(&mut file_buffer).unwrap();
self.wallet = Arc::new(lw);
println!("[OK]");
}
pub fn do_save(&self) {
print!("Saving wallet...");
io::stdout().flush().ok().expect("Could not flush stdout");
let mut file_buffer = File::create("wallet.dat").unwrap();
self.wallet.write(&mut file_buffer).unwrap();
println!("[OK]");
}