cleanup bitcoind module dep to app config

This commit is contained in:
edouard 2023-08-30 18:40:43 +02:00
parent 3704995906
commit c756969e72
3 changed files with 24 additions and 18 deletions

View File

@ -1,9 +1,8 @@
use liana::{config::BitcoindConfig, miniscript::bitcoin};
use std::path::Path;
use tracing::{info, warn};
use crate::app::config::InternalBitcoindExeConfig;
#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;
@ -51,10 +50,10 @@ impl std::fmt::Display for StartInternalBitcoindError {
/// Start internal bitcoind for the given network.
pub fn start_internal_bitcoind(
network: &bitcoin::Network,
exe_config: InternalBitcoindExeConfig,
bitcoind_datadir: &Path,
exe_path: &Path,
) -> Result<std::process::Child, StartInternalBitcoindError> {
let datadir_path_str = exe_config
.data_dir
let datadir_path_str = bitcoind_datadir
.canonicalize()
.map_err(|e| StartInternalBitcoindError::CouldNotCanonicalizeDataDir(e.to_string()))?
.to_str()
@ -71,7 +70,7 @@ pub fn start_internal_bitcoind(
format!("-chain={}", network.to_core_arg()),
format!("-datadir={}", datadir_path_str),
];
let mut command = std::process::Command::new(exe_config.exe_path);
let mut command = std::process::Command::new(exe_path);
#[cfg(target_os = "windows")]
let command = command.creation_flags(CREATE_NO_WINDOW);
command

View File

@ -865,16 +865,19 @@ impl Step for InternalBitcoindStep {
return Command::none();
}
};
let handle =
match start_internal_bitcoind(&self.network, exe_config.clone()) {
Err(e) => {
self.started = Some(Err(
StartInternalBitcoindError::CommandError(e.to_string()),
));
return Command::none();
}
Ok(h) => h,
};
let handle = match start_internal_bitcoind(
&self.network,
&exe_config.data_dir,
&exe_config.exe_path,
) {
Err(e) => {
self.started = Some(Err(StartInternalBitcoindError::CommandError(
e.to_string(),
)));
return Command::none();
}
Ok(h) => h,
};
// Need to wait for cookie file to appear.
let cookie_path =
internal_bitcoind_cookie_path(&self.bitcoind_datadir, &self.network);

View File

@ -361,8 +361,12 @@ pub async fn start_bitcoind_and_daemon(
info!("Internal bitcoind is already running");
} else {
info!("Starting internal bitcoind");
start_internal_bitcoind(&config.bitcoin_config.network, exe_config)
.map_err(Error::Bitcoind)?;
start_internal_bitcoind(
&config.bitcoin_config.network,
&exe_config.data_dir,
&exe_config.exe_path,
)
.map_err(Error::Bitcoind)?;
if !utils::poll_for_file(&bitcoind_config.cookie_path, 200, 15) {
return Err(Error::Bitcoind(
StartInternalBitcoindError::CookieFileNotFound(