SilentPaymentWallet::save() takes an already unlocked wallet as argument

This commit is contained in:
NicolasCantu 2025-01-17 09:19:01 +01:00
parent 8d7a6c7400
commit 1d1b3546d6
2 changed files with 6 additions and 6 deletions

View File

@ -147,9 +147,9 @@ impl SilentPaymentWallet {
self.sp_wallet.lock_anyhow() self.sp_wallet.lock_anyhow()
} }
pub fn save(&self) -> Result<()> { // This is terrible design
let wallet = self.sp_wallet.lock_anyhow()?.clone(); pub fn save(&self, unlocked_wallet: MutexGuard<SpWallet>) -> Result<()> {
let value = serde_json::from_str(&serde_json::to_string(&wallet)?)?; let value = serde_json::from_str(&serde_json::to_string(&unlocked_wallet.clone())?)?;
self.storage.lock_anyhow()?.save(&value) self.storage.lock_anyhow()?.save(&value)
} }
} }
@ -467,7 +467,7 @@ async fn main() -> Result<()> {
}) })
.expect("Failed to initialize WALLET"); .expect("Failed to initialize WALLET");
WALLET.get().unwrap().save().unwrap(); WALLET.get().unwrap().save(WALLET.get().unwrap().get_wallet()?).unwrap();
CACHEDPROCESSES CACHEDPROCESSES
.set(Mutex::new(cached_processes)) .set(Mutex::new(cached_processes))

View File

@ -93,7 +93,7 @@ pub fn check_transaction_alone(tx: &Transaction, tweak_data: &PublicKey) -> Resu
}; };
if updates.len() > 0 { if updates.len() > 0 {
sp_wallet.save()?; WALLET.get().unwrap().save(wallet)?;
} }
Ok(updates) Ok(updates)
@ -339,7 +339,7 @@ pub fn scan_blocks(mut n_blocks_to_scan: u32, electrum_url: &str) -> anyhow::Res
.get_wallet()? .get_wallet()?
.get_mut_outputs() .get_mut_outputs()
.update_last_scan(end); .update_last_scan(end);
sp_wallet.save()?; WALLET.get().unwrap().save(wallet)?;
Ok(()) Ok(())
} }