Automatically load and save wallet
This commit is contained in:
@@ -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]");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user