Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion zingolib/src/lightclient/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ impl LightClient {
let save_handle = tokio::spawn(async move {
loop {
interval.tick().await;
if let Some(wallet_bytes) = wallet.write().await.save()? {
let mut wallet_guard = wallet.write().await;
if let Some(wallet_bytes) = wallet_guard.save()? {
write_to_path(&wallet_path, &wallet_bytes)?;
wallet_guard.save_required = false;
}
if !save_active.load(atomic::Ordering::Acquire) {
return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@ impl LightWallet {
///
/// Intended to be called from a save task which calls `save` in a loop, awaiting the wallet lock and checking
/// `self.save_required` status, writing the returned wallet bytes to persistance.
/// `save_required` field must be manually set back to false after wallet data has been successfully persisted to disk.
pub fn save(&mut self) -> std::io::Result<Option<Vec<u8>>> {
if self.save_required {
let chain_type = self.chain_type;
let mut wallet_bytes: Vec<u8> = vec![];
self.write(&mut wallet_bytes, &chain_type)?;
self.save_required = false;
Ok(Some(wallet_bytes))
} else {
Ok(None)
Expand Down