-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gui: add option to use internal bitcoind
During installation, the user may choose for Liana to configure and start bitcoind for them. This internal bitcoind uses as its data directory the `bitcoind_datadir` folder within the Liana data directory. If the internal bitcoind option has been selected for a network, it will be automatically started when the user returns to Liana and stopped when Liana is closed.
- Loading branch information
Showing
14 changed files
with
1,049 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use liana::{config::BitcoindConfig, miniscript::bitcoin}; | ||
|
||
use tracing::{info, warn}; | ||
|
||
use crate::app::config::InternalBitcoindExeConfig; | ||
|
||
/// Possible errors when starting bitcoind. | ||
#[derive(PartialEq, Eq, Debug, Clone)] | ||
pub enum StartInternalBitcoindError { | ||
CommandError(String), | ||
CouldNotCanonicalizeDataDir(String), | ||
CouldNotCanonicalizeCookiePath(String), | ||
CookieFileNotFound(String), | ||
BitcoinDError(String), | ||
} | ||
|
||
impl std::fmt::Display for StartInternalBitcoindError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
match self { | ||
Self::CommandError(e) => { | ||
write!(f, "Command to start bitcoind returned an error: {}", e) | ||
} | ||
Self::CouldNotCanonicalizeDataDir(e) => { | ||
write!(f, "Failed to canonicalize datadir: {}", e) | ||
} | ||
Self::CouldNotCanonicalizeCookiePath(e) => { | ||
write!(f, "Failed to canonicalize cookie path: {}", e) | ||
} | ||
Self::CookieFileNotFound(path) => { | ||
write!( | ||
f, | ||
"Cookie file was not found at the expected path: {}", | ||
path | ||
) | ||
} | ||
Self::BitcoinDError(e) => write!(f, "bitcoind connection check failed: {}", e), | ||
} | ||
} | ||
} | ||
|
||
/// Start internal bitcoind for the given network. | ||
pub fn start_internal_bitcoind( | ||
network: &bitcoin::Network, | ||
exe_config: InternalBitcoindExeConfig, | ||
) -> Result<std::process::Child, StartInternalBitcoindError> { | ||
let args = vec![ | ||
format!("-chain={}", network.to_core_arg()), | ||
format!( | ||
"-datadir={}", | ||
exe_config | ||
.data_dir | ||
.canonicalize() | ||
.map_err(|e| StartInternalBitcoindError::CouldNotCanonicalizeDataDir( | ||
e.to_string() | ||
))? | ||
.to_string_lossy() | ||
), | ||
]; | ||
std::process::Command::new(exe_config.exe_path) | ||
.args(&args) | ||
.stdout(std::process::Stdio::null()) // We still get bitcoind's logs in debug.log. | ||
.spawn() | ||
.map_err(|e| StartInternalBitcoindError::CommandError(e.to_string())) | ||
} | ||
|
||
/// Stop (internal) bitcoind. | ||
pub fn stop_internal_bitcoind(bitcoind_config: &BitcoindConfig) { | ||
match liana::BitcoinD::new(bitcoind_config, "internal_bitcoind_stop".to_string()) { | ||
Ok(bitcoind) => { | ||
info!("Stopping internal bitcoind..."); | ||
bitcoind.stop(); | ||
} | ||
Err(e) => { | ||
warn!("Could not create interface to internal bitcoind: '{}'.", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.