diff --git a/src/main.rs b/src/main.rs index f76a0b9..78c9f4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,9 +147,9 @@ impl SilentPaymentWallet { self.sp_wallet.lock_anyhow() } - pub fn save(&self) -> Result<()> { - let wallet = self.sp_wallet.lock_anyhow()?.clone(); - let value = serde_json::from_str(&serde_json::to_string(&wallet)?)?; + // This is terrible design + pub fn save(&self, unlocked_wallet: MutexGuard) -> Result<()> { + let value = serde_json::from_str(&serde_json::to_string(&unlocked_wallet.clone())?)?; self.storage.lock_anyhow()?.save(&value) } } @@ -467,7 +467,7 @@ async fn main() -> Result<()> { }) .expect("Failed to initialize WALLET"); - WALLET.get().unwrap().save().unwrap(); + WALLET.get().unwrap().save(WALLET.get().unwrap().get_wallet()?).unwrap(); CACHEDPROCESSES .set(Mutex::new(cached_processes)) diff --git a/src/scan.rs b/src/scan.rs index b482388..37a1b91 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -93,7 +93,7 @@ pub fn check_transaction_alone(tx: &Transaction, tweak_data: &PublicKey) -> Resu }; if updates.len() > 0 { - sp_wallet.save()?; + WALLET.get().unwrap().save(wallet)?; } Ok(updates) @@ -339,7 +339,7 @@ pub fn scan_blocks(mut n_blocks_to_scan: u32, electrum_url: &str) -> anyhow::Res .get_wallet()? .get_mut_outputs() .update_last_scan(end); - sp_wallet.save()?; + WALLET.get().unwrap().save(wallet)?; Ok(()) }