diff --git a/gui/src/bitcoind.rs b/gui/src/bitcoind.rs index ef3acc5a..07ad7b14 100644 --- a/gui/src/bitcoind.rs +++ b/gui/src/bitcoind.rs @@ -217,15 +217,21 @@ impl Bitcoind { /// Stop (internal) bitcoind. pub fn stop(&self) { - match liana::BitcoinD::new(&self.config, "internal_bitcoind_stop".to_string()) { - Ok(bitcoind) => { - info!("Stopping internal bitcoind..."); - bitcoind.stop(); - info!("Stopped liana managed bitcoind"); - } - Err(e) => { - warn!("Could not create interface to internal bitcoind: '{}'.", e); - } + stop_bitcoind(&self.config); + } +} + +pub fn stop_bitcoind(config: &BitcoindConfig) -> bool { + match liana::BitcoinD::new(config, "internal_bitcoind_stop".to_string()) { + Ok(bitcoind) => { + info!("Stopping internal bitcoind..."); + bitcoind.stop(); + info!("Stopped liana managed bitcoind"); + true + } + Err(e) => { + warn!("Could not create interface to internal bitcoind: '{}'.", e); + false } } } diff --git a/gui/src/loader.rs b/gui/src/loader.rs index cfdd5c80..9fb43147 100644 --- a/gui/src/loader.rs +++ b/gui/src/loader.rs @@ -27,7 +27,7 @@ use crate::{ config::Config as GUIConfig, wallet::{Wallet, WalletError}, }, - bitcoind::{Bitcoind, StartInternalBitcoindError}, + bitcoind::{stop_bitcoind, Bitcoind, StartInternalBitcoindError}, daemon::{client, embedded::EmbeddedDaemon, model::*, Daemon, DaemonError}, }; @@ -225,6 +225,15 @@ impl Loader { if let Some(bitcoind) = &self.internal_bitcoind { bitcoind.stop(); + } else if self.gui_config.start_internal_bitcoind { + if let Ok(config) = Config::from_file(self.gui_config.daemon_config_path.clone()) { + if let Some(bitcoind_config) = &config.bitcoind_config { + let mut stopped = false; + while !stopped { + stopped = stop_bitcoind(&bitcoind_config); + } + } + } } }