From 5905ef728b2813a646e21870ae91c4f568e87bb1 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Fri, 18 Oct 2019 15:38:16 -0700 Subject: [PATCH] Save in non-interactive mode --- lib/src/lightclient.rs | 18 ++++++++++++++---- src/main.rs | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 2afb5db..e527c2d 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -333,10 +333,20 @@ impl LightClient { 1_000_000, // 1 MB write buffer File::create(self.config.get_wallet_path()).unwrap()); - self.wallet.write(&mut file_buffer).unwrap(); - info!("Saved wallet"); - - format!("Saved Wallet") + match self.wallet.write(&mut file_buffer) { + Ok(_) => { + info!("Saved wallet"); + let response = object!{ + "result" => "success" + }; + response.pretty(2) + }, + Err(e) => { + let err = format!("ERR: {}", e); + error!("{}", err); + err + } + } } pub fn get_server_uri(&self) -> http::Uri { diff --git a/src/main.rs b/src/main.rs index 6881f8b..96fde21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -137,6 +137,10 @@ pub fn main() { error!("{}", e); } } + + // Save before exit + command_tx.send(("save".to_string(), vec![])).unwrap(); + resp_rx.recv().unwrap(); } }