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 ea09ce1
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 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 @@ -198,20 +209,30 @@ impl ElectrsD {
args.push("--network");
args.push(conf.network);

use std::io::Read;
#[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")]
let mut cookie_value;
#[cfg(feature = "legacy")]
{
use std::io::Read;
args.push("--cookie");
let mut cookie = std::fs::File::open(&bitcoind.params.cookie_file)?;
cookie_value = String::new();
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 ea09ce1

Please # to comment.