Save and Read wallet

This commit is contained in:
Aditya Kulkarni
2019-09-06 13:13:14 -07:00
parent 81b6b52ba0
commit 7ebc8686ed
6 changed files with 284 additions and 28 deletions

View File

@@ -1,11 +1,12 @@
use crate::lightwallet::LightWallet;
use std::fs::File;
use std::io::prelude::*;
use std::sync::Arc;
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use std::error::Error;
use std::io::prelude::*;
use std::fs::File;
use zcash_primitives::transaction::{TxId, Transaction};
use zcash_primitives::note_encryption::Memo;
@@ -60,6 +61,20 @@ impl LightClient {
println!("Balance: {}", self.wallet.balance());
}
pub fn do_read(&mut self) {
let mut file_buffer = File::open("wallet.dat").unwrap();
let lw = LightWallet::read(&mut file_buffer).unwrap();
self.wallet = Arc::new(lw);
}
pub fn do_save(&self) {
let mut file_buffer = File::create("wallet.dat").unwrap();
self.wallet.write(&mut file_buffer).unwrap();
}
pub fn do_info(&self) {
let uri: http::Uri = format!("http://127.0.0.1:9067").parse().unwrap();