lib: on Windows unload the watchonly wallet before deleting it

This commit is contained in:
Antoine Poinsot 2023-05-11 11:47:36 +02:00
parent b55d76af57
commit 17d1f847bc
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 9 additions and 1 deletions

View File

@ -446,7 +446,7 @@ impl BitcoinD {
.collect()
}
fn unload_wallet(&self, wallet_path: String) -> Option<String> {
pub fn unload_wallet(&self, wallet_path: String) -> Option<String> {
self.make_node_request("unloadwallet", &params!(Json::String(wallet_path),))
.get("warning")
.expect("No 'warning' in 'unloadwallet' response?")

View File

@ -201,6 +201,7 @@ fn setup_sqlite(
// Windows-specific utility to remove a leftover watchonly wallet within bitcoind's datadir.
#[cfg(windows)]
fn maybe_delete_watchonly_wallet(
bitcoind: &BitcoinD,
bitcoind_cookie_path: &path::Path,
bitcoin_net: miniscript::bitcoin::Network,
wallet_name: &str,
@ -228,6 +229,12 @@ fn maybe_delete_watchonly_wallet(
"Found a leftover watchonly wallet at '{}'. Deleting it.",
wallet_path.as_path().to_string_lossy()
);
if let Some(warning) = bitcoind.unload_wallet(wallet_path.to_string_lossy().to_string()) {
log::warn!(
"Warning when unloading watchonly wallet on bitcoind: '{}'",
warning
);
}
fs::remove_dir_all(&wallet_path)
.map_err(|e| StartupError::WindowsBitcoindWatchonlyDeletion(wallet_path, e))?;
} else {
@ -275,6 +282,7 @@ fn setup_bitcoind(
// any leftover Liana watchonly wallet from bitcoind's data dir.
#[cfg(windows)]
maybe_delete_watchonly_wallet(
&bitcoind,
&bitcoind_config.cookie_path,
config.bitcoin_config.network,
wo_name,