Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: windows: don't unload the wo wallet if not loaded #651

Merged
Merged
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
24 changes: 14 additions & 10 deletions src/bitcoin/d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl BitcoinD {
None
}

pub fn unload_wallet(&self, wallet_path: String) -> Option<String> {
fn unload_wallet(&self, wallet_path: String) -> Option<String> {
let res = self.make_node_request("unloadwallet", &params!(Json::String(wallet_path),));
self.warning_from_res(&res)
}
Expand Down Expand Up @@ -607,23 +607,27 @@ impl BitcoinD {
.collect()
}

/// Create the watchonly wallet on bitcoind, and import it the main descriptor.
pub fn create_watchonly_wallet(
&self,
main_descriptor: &LianaDescriptor,
) -> Result<(), BitcoindError> {
// Remove any leftover. This can happen if we delete the watchonly wallet but don't restart
// bitcoind.
while self.list_wallets().contains(&self.watchonly_wallet_path) {
pub fn maybe_unload_watchonly_wallet(&self, watchonly_wallet_path: String) {
while self.list_wallets().contains(&watchonly_wallet_path) {
log::info!("Found a leftover watchonly wallet loaded on bitcoind. Removing it.");
if let Some(e) = self.unload_wallet(self.watchonly_wallet_path.clone()) {
if let Some(e) = self.unload_wallet(watchonly_wallet_path.clone()) {
log::error!(
"Unloading wallet '{}': '{}'",
&self.watchonly_wallet_path,
e
);
}
}
}

/// Create the watchonly wallet on bitcoind, and import it the main descriptor.
pub fn create_watchonly_wallet(
&self,
main_descriptor: &LianaDescriptor,
) -> Result<(), BitcoindError> {
// Remove any leftover. This can happen if we delete the watchonly wallet but don't restart
// bitcoind.
self.maybe_unload_watchonly_wallet(self.watchonly_wallet_path.clone());

// Now create the wallet and import the main descriptor.
self.create_wallet(self.watchonly_wallet_path.clone())
Expand Down
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,11 @@ fn maybe_delete_watchonly_wallet(
};

if wallet_path.exists() {
bitcoind.maybe_unload_watchonly_wallet(wallet_path.to_string_lossy().to_string());
log::info!(
"Found a leftover watchonly wallet at '{}'. Deleting it.",
"Deleting the leftover watchonly wallet at '{}'.",
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 {
Expand Down
Loading