2024-02-23 14:04:27 -05:00
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
2021-03-24 02:49:19 -04:00
|
|
|
use crate::harness::bitcoind;
|
2021-02-01 18:39:34 -05:00
|
|
|
use bitcoin::Network;
|
2024-02-23 14:04:27 -05:00
|
|
|
use testcontainers::{core::WaitFor, Image, ImageArgs};
|
2021-02-01 18:39:34 -05:00
|
|
|
|
|
|
|
pub const HTTP_PORT: u16 = 60401;
|
|
|
|
pub const RPC_PORT: u16 = 3002;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Electrs {
|
|
|
|
tag: String,
|
|
|
|
args: ElectrsArgs,
|
|
|
|
entrypoint: Option<String>,
|
|
|
|
wait_for_message: String,
|
2024-02-23 14:04:27 -05:00
|
|
|
volumes: BTreeMap<String, String>,
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Image for Electrs {
|
|
|
|
type Args = ElectrsArgs;
|
2024-02-23 14:04:27 -05:00
|
|
|
fn name(&self) -> String {
|
|
|
|
"vulpemventures/electrs".into()
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
2024-02-23 14:04:27 -05:00
|
|
|
fn tag(&self) -> String {
|
|
|
|
self.tag.clone()
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
2024-02-23 14:04:27 -05:00
|
|
|
fn ready_conditions(&self) -> Vec<WaitFor> {
|
|
|
|
vec![WaitFor::message_on_stderr(self.wait_for_message.clone())]
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
2024-02-23 14:04:27 -05:00
|
|
|
fn volumes(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
|
|
|
|
Box::new(self.volumes.iter())
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn entrypoint(&self) -> Option<String> {
|
|
|
|
self.entrypoint.to_owned()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Electrs {
|
|
|
|
fn default() -> Self {
|
|
|
|
Electrs {
|
|
|
|
tag: "v0.16.0.3".into(),
|
|
|
|
args: ElectrsArgs::default(),
|
|
|
|
entrypoint: Some("/build/electrs".into()),
|
|
|
|
wait_for_message: "Running accept thread".to_string(),
|
2024-02-23 14:04:27 -05:00
|
|
|
volumes: BTreeMap::default(),
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Electrs {
|
|
|
|
pub fn with_tag(self, tag_str: &str) -> Self {
|
|
|
|
Electrs {
|
|
|
|
tag: tag_str.to_string(),
|
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_volume(mut self, volume: String) -> Self {
|
2024-02-23 14:04:27 -05:00
|
|
|
self.volumes.insert(volume, bitcoind::DATADIR.to_string());
|
2021-02-01 18:39:34 -05:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_daemon_rpc_addr(mut self, name: String) -> Self {
|
|
|
|
self.args.daemon_rpc_addr = name;
|
|
|
|
self
|
|
|
|
}
|
2024-02-23 14:04:27 -05:00
|
|
|
|
|
|
|
pub fn self_and_args(self) -> (Self, ElectrsArgs) {
|
|
|
|
let args = self.args.clone();
|
|
|
|
(self, args)
|
|
|
|
}
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct ElectrsArgs {
|
|
|
|
pub network: Network,
|
|
|
|
pub daemon_dir: String,
|
|
|
|
pub daemon_rpc_addr: String,
|
|
|
|
pub cookie: String,
|
|
|
|
pub http_addr: String,
|
|
|
|
pub electrum_rpc_addr: String,
|
|
|
|
pub cors: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ElectrsArgs {
|
|
|
|
fn default() -> Self {
|
|
|
|
// todo: these "defaults" are only suitable for our tests and need to be looked
|
|
|
|
// at
|
|
|
|
ElectrsArgs {
|
|
|
|
network: Network::Regtest,
|
|
|
|
daemon_dir: bitcoind::DATADIR.to_string(),
|
|
|
|
daemon_rpc_addr: format!("0.0.0.0:{}", bitcoind::RPC_PORT),
|
|
|
|
cookie: format!("{}:{}", bitcoind::RPC_USER, bitcoind::RPC_PASSWORD),
|
|
|
|
http_addr: format!("0.0.0.0:{}", HTTP_PORT),
|
|
|
|
electrum_rpc_addr: format!("0.0.0.0:{}", RPC_PORT),
|
|
|
|
cors: "*".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoIterator for ElectrsArgs {
|
|
|
|
type Item = String;
|
|
|
|
type IntoIter = ::std::vec::IntoIter<String>;
|
|
|
|
|
|
|
|
fn into_iter(self) -> <Self as IntoIterator>::IntoIter {
|
|
|
|
let mut args = Vec::new();
|
|
|
|
|
|
|
|
match self.network {
|
|
|
|
Network::Testnet => args.push("--network=testnet".to_string()),
|
|
|
|
Network::Regtest => args.push("--network=regtest".to_string()),
|
|
|
|
Network::Bitcoin => {}
|
2021-02-17 21:33:50 -05:00
|
|
|
Network::Signet => panic!("signet not yet supported"),
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
args.push("-vvvvv".to_string());
|
2024-02-23 14:04:27 -05:00
|
|
|
args.push(format!("--daemon-dir={}", self.daemon_dir.as_str()));
|
2021-02-01 18:39:34 -05:00
|
|
|
args.push(format!("--daemon-rpc-addr={}", self.daemon_rpc_addr));
|
|
|
|
args.push(format!("--cookie={}", self.cookie));
|
|
|
|
args.push(format!("--http-addr={}", self.http_addr));
|
|
|
|
args.push(format!("--electrum-rpc-addr={}", self.electrum_rpc_addr));
|
|
|
|
args.push(format!("--cors={}", self.cors));
|
|
|
|
|
|
|
|
args.into_iter()
|
|
|
|
}
|
|
|
|
}
|
2024-02-23 14:04:27 -05:00
|
|
|
|
|
|
|
impl ImageArgs for ElectrsArgs {
|
|
|
|
fn into_iterator(self) -> Box<dyn Iterator<Item = String>> {
|
|
|
|
Box::new(self.into_iter())
|
|
|
|
}
|
|
|
|
}
|