Skip to content

Commit

Permalink
add backend-type in conf
Browse files Browse the repository at this point in the history
  • Loading branch information
pythcoiner committed Sep 25, 2024
1 parent d0e740d commit 06cae4f
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ pub use electrum_client;
pub use error::Error;
pub use which;

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Backend {
Electrs,
Esplora,
Mempool,
}

/// Electrs configuration parameters, implements a convenient [Default] for most common use.
///
/// Default values:
Expand Down Expand Up @@ -81,6 +88,9 @@ pub struct Conf<'a> {
/// Persistent directory path
pub staticdir: Option<PathBuf>,

/// The backend type in use
pub backend: Backend,

/// Try to spawn the process `attempt` time
///
/// The OS is giving available ports to use, however, they aren't booked, so it could rarely
Expand Down Expand Up @@ -110,6 +120,7 @@ impl Default for Conf<'_> {
staticdir: None,
attempts: 3,
buffered_logs: false,
backend: Backend::Electrs,
}
}
}
Expand Down Expand Up @@ -201,10 +212,20 @@ impl ElectrsD {
#[cfg(not(feature = "legacy"))]
let cookie_file;
#[cfg(not(feature = "legacy"))]
let cookie_value;
#[cfg(not(feature = "legacy"))]
{
args.push("--cookie-file");
cookie_file = format!("{}", bitcoind.params.cookie_file.display());
args.push(&cookie_file);
if let Backend::Mempool = conf.backend {
args.push("--cookie");
let mut cookie = std::fs::File::open(&bitcoind.params.cookie_file)?;
cookie_value = String::new();
cookie.read_to_string(&mut cookie_value)?;
args.push(&cookie_value);
} else {
args.push("--cookie-file");
cookie_file = format!("{}", bitcoind.params.cookie_file.display());
args.push(&cookie_file);
}
}

#[cfg(feature = "legacy")]
Expand All @@ -227,6 +248,7 @@ impl ElectrsD {
if cfg!(feature = "electrs_0_8_10")
|| cfg!(feature = "esplora_a33e97e1")
|| cfg!(feature = "legacy")
|| conf.backend == Backend::Mempool
{
args.push("--jsonrpc-import");
} else {
Expand Down

0 comments on commit 06cae4f

Please sign in to comment.