mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-01-30 18:42:15 +00:00
Fix save command return value
This commit is contained in:
parent
c3af5a1ca2
commit
e4f00a78d5
@ -310,7 +310,19 @@ impl Command for SaveCommand {
|
||||
}
|
||||
|
||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
||||
lightclient.do_save()
|
||||
match lightclient.do_save() {
|
||||
Ok(_) => {
|
||||
let r = object!{ "result" => "success" };
|
||||
r.pretty(2)
|
||||
},
|
||||
Err(e) => {
|
||||
let r = object!{
|
||||
"result" => "error",
|
||||
"error" => e
|
||||
};
|
||||
r.pretty(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -490,7 +502,10 @@ impl Command for QuitCommand {
|
||||
}
|
||||
|
||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
||||
lightclient.do_save()
|
||||
match lightclient.do_save() {
|
||||
Ok(_) => {"".to_string()},
|
||||
Err(e) => e
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,23 +331,17 @@ impl LightClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn do_save(&self) -> String {
|
||||
pub fn do_save(&self) -> Result<(), String> {
|
||||
let mut file_buffer = BufWriter::with_capacity(
|
||||
1_000_000, // 1 MB write buffer
|
||||
File::create(self.config.get_wallet_path()).unwrap());
|
||||
|
||||
match self.wallet.write().unwrap().write(&mut file_buffer) {
|
||||
Ok(_) => {
|
||||
info!("Saved wallet");
|
||||
let response = object!{
|
||||
"result" => "success"
|
||||
};
|
||||
response.pretty(2)
|
||||
},
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => {
|
||||
let err = format!("ERR: {}", e);
|
||||
error!("{}", err);
|
||||
err
|
||||
Err(e.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user