Prevent saves on ios/android

This commit is contained in:
Aditya Kulkarni 2020-05-19 10:15:06 -07:00
parent 4c8442fa38
commit 4f56ba82a0

View File

@ -609,37 +609,43 @@ impl LightClient {
} }
pub fn do_save(&self) -> Result<(), String> { pub fn do_save(&self) -> Result<(), String> {
// If the wallet is encrypted but unlocked, lock it again. // On mobile platforms, disable the save, because the saves will be handled by the native layer, and not in rust
{ if cfg!(all(not(target_os="ios"), not(target_os="android"))) {
let mut wallet = self.wallet.write().unwrap(); // If the wallet is encrypted but unlocked, lock it again.
if wallet.is_encrypted() && wallet.is_unlocked_for_spending() { {
match wallet.lock() { let mut wallet = self.wallet.write().unwrap();
Ok(_) => {}, if wallet.is_encrypted() && wallet.is_unlocked_for_spending() {
Err(e) => { match wallet.lock() {
let err = format!("ERR: {}", e); Ok(_) => {},
error!("{}", err); Err(e) => {
return Err(e.to_string()); let err = format!("ERR: {}", e);
error!("{}", err);
return Err(e.to_string());
}
} }
} }
} }
}
let mut file_buffer = BufWriter::with_capacity( let mut file_buffer = BufWriter::with_capacity(
1_000_000, // 1 MB write buffer 1_000_000, // 1 MB write buffer
File::create(self.config.get_wallet_path()).unwrap()); File::create(self.config.get_wallet_path()).unwrap());
let r = match self.wallet.write().unwrap().write(&mut file_buffer) { let r = match self.wallet.write().unwrap().write(&mut file_buffer) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(e) => { Err(e) => {
let err = format!("ERR: {}", e); let err = format!("ERR: {}", e);
error!("{}", err); error!("{}", err);
Err(e.to_string()) Err(e.to_string())
} }
}; };
file_buffer.flush().map_err(|e| format!("{}", e))?; file_buffer.flush().map_err(|e| format!("{}", e))?;
r r
} else {
// On ios and android just return OK
Ok(())
}
} }