2024-02-23 14:04:27 -05:00
|
|
|
use std::collections::BTreeMap;
|
|
|
|
use testcontainers::{core::WaitFor, Image, ImageArgs};
|
2021-02-01 18:39:34 -05:00
|
|
|
|
|
|
|
pub const RPC_USER: &str = "admin";
|
|
|
|
pub const RPC_PASSWORD: &str = "123";
|
|
|
|
pub const RPC_PORT: u16 = 18443;
|
|
|
|
pub const PORT: u16 = 18886;
|
|
|
|
pub const DATADIR: &str = "/home/bdk";
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Bitcoind {
|
|
|
|
entrypoint: Option<String>,
|
2024-02-23 14:04:27 -05:00
|
|
|
volumes: BTreeMap<String, String>,
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Image for Bitcoind {
|
|
|
|
type Args = BitcoindArgs;
|
|
|
|
|
2024-02-23 14:04:27 -05:00
|
|
|
fn name(&self) -> String {
|
|
|
|
"coblox/bitcoin-core".into()
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
|
2024-02-23 14:04:27 -05:00
|
|
|
fn tag(&self) -> String {
|
|
|
|
"0.21.0".into()
|
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_stdout("init message: Done loading")]
|
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 Bitcoind {
|
|
|
|
fn default() -> Self {
|
|
|
|
Bitcoind {
|
|
|
|
entrypoint: Some("/usr/bin/bitcoind".into()),
|
2024-02-23 14:04:27 -05:00
|
|
|
volumes: BTreeMap::default(),
|
2021-02-01 18:39:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Bitcoind {
|
|
|
|
pub fn with_volume(mut self, volume: String) -> Self {
|
2024-02-23 14:04:27 -05:00
|
|
|
self.volumes.insert(volume, DATADIR.to_string());
|
2021-02-01 18:39:34 -05:00
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct BitcoindArgs;
|
|
|
|
|
|
|
|
impl Default for BitcoindArgs {
|
|
|
|
fn default() -> Self {
|
|
|
|
BitcoindArgs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoIterator for BitcoindArgs {
|
|
|
|
type Item = String;
|
|
|
|
type IntoIter = ::std::vec::IntoIter<String>;
|
|
|
|
|
|
|
|
fn into_iter(self) -> <Self as IntoIterator>::IntoIter {
|
|
|
|
let args = vec![
|
|
|
|
"-server".to_string(),
|
|
|
|
"-regtest".to_string(),
|
|
|
|
"-listen=1".to_string(),
|
|
|
|
"-prune=0".to_string(),
|
|
|
|
"-rpcallowip=0.0.0.0/0".to_string(),
|
|
|
|
"-rpcbind=0.0.0.0".to_string(),
|
|
|
|
format!("-rpcuser={}", RPC_USER),
|
|
|
|
format!("-rpcpassword={}", RPC_PASSWORD),
|
|
|
|
"-printtoconsole".to_string(),
|
|
|
|
"-fallbackfee=0.0002".to_string(),
|
|
|
|
format!("-datadir={}", DATADIR),
|
|
|
|
format!("-rpcport={}", RPC_PORT),
|
|
|
|
format!("-port={}", PORT),
|
|
|
|
"-rest".to_string(),
|
|
|
|
];
|
|
|
|
|
|
|
|
args.into_iter()
|
|
|
|
}
|
|
|
|
}
|
2024-02-23 14:04:27 -05:00
|
|
|
|
|
|
|
impl ImageArgs for BitcoindArgs {
|
|
|
|
fn into_iterator(self) -> Box<dyn Iterator<Item = String>> {
|
|
|
|
Box::new(self.into_iter())
|
|
|
|
}
|
|
|
|
}
|