|
| 1 | +use std::net::SocketAddrV4; |
| 2 | +use std::sync::Arc; |
| 3 | +use std::time::Duration; |
| 4 | + |
1 | 5 | /// Bitcoin regtest environment using electrsd with automatic executable downloads |
2 | 6 | use anyhow::{Context, Result}; |
3 | 7 | use bdk_electrum::bdk_core::bitcoin::{KnownHrp, XOnlyPublicKey}; |
4 | 8 | use bdk_electrum::BdkElectrumClient; |
5 | | - |
6 | | - |
| 9 | +use bdk_wallet::bitcoin::address::NetworkChecked; |
7 | 10 | use bdk_wallet::bitcoin::key::Secp256k1; |
8 | 11 | use bdk_wallet::bitcoin::secp256k1::All; |
9 | | -use bdk_wallet::bitcoin::{address::NetworkChecked, Address, Amount, BlockHash, Network, Transaction, Txid}; |
| 12 | +use bdk_wallet::bitcoin::{Address, Amount, BlockHash, Network, Transaction, Txid}; |
10 | 13 | use corepc_node::get_available_port; |
11 | | -use electrsd::corepc_node; |
12 | | -use electrsd::electrum_client::Client; |
13 | | -use electrsd::{corepc_node::Node, electrum_client::ElectrumApi, ElectrsD}; |
| 14 | +use electrsd::corepc_node::Node; |
| 15 | +use electrsd::electrum_client::{Client, ElectrumApi}; |
| 16 | +use electrsd::{corepc_node, ElectrsD}; |
14 | 17 | use hmac::{Hmac, Mac}; |
15 | 18 | use rand::{Rng, RngCore}; |
16 | 19 | use secp::Scalar; |
17 | 20 | use sha2::Sha256; |
18 | 21 | use simple_semaphore::{Permit, Semaphore}; |
19 | | -use std::sync::Arc; |
20 | | -use std::time::Duration; |
21 | 22 | use tempfile::{tempdir, TempDir}; |
22 | 23 |
|
23 | 24 |
|
@@ -54,6 +55,7 @@ impl Default for Config<'_> { |
54 | 55 | let mut conf = corepc_node::Conf::default(); |
55 | 56 | // Listen on all interfaces (0.0.0.0) instead of just localhost |
56 | 57 | conf.args.push("-rpcbind=0.0.0.0"); |
| 58 | + conf.args.push("-listen=1"); |
57 | 59 |
|
58 | 60 | // Allow connections from any IP (use 0.0.0.0/0 for "everywhere") |
59 | 61 | conf.args.push("-rpcallowip=0.0.0.0/0"); |
@@ -173,6 +175,7 @@ impl TestEnv { |
173 | 175 |
|
174 | 176 | let auth_config = format!("-{}", rpc_auth); |
175 | 177 | let mut bitcoin_config = config.bitcoind.clone(); |
| 178 | + bitcoin_config.p2p = corepc_node::P2P::Yes; |
176 | 179 | bitcoin_config.args.push(&*auth_config); |
177 | 180 |
|
178 | 181 | let bitcoind = match std::env::var("BITCOIND_EXEC") { |
@@ -243,7 +246,7 @@ impl TestEnv { |
243 | 246 | let bitcoind_rpc_port = self.bitcoind.params.rpc_socket.port(); |
244 | 247 | let browserport = get_available_port()?; |
245 | 248 |
|
246 | | - let electrum_port = self.electrsd.electrum_url.split(':').last() |
| 249 | + let electrum_port = self.electrsd.electrum_url.split(':').next_back() |
247 | 250 | .context("Failed to parse electrum port")?; |
248 | 251 |
|
249 | 252 | let container_name = format!("btc-explorer-{}", browserport); |
@@ -439,6 +442,11 @@ impl TestEnv { |
439 | 442 | pub fn workdir(&self) -> std::path::PathBuf { |
440 | 443 | self.electrsd.workdir() |
441 | 444 | } |
| 445 | + |
| 446 | + /// Get the running bitcoind socket address |
| 447 | + pub fn p2p_socket_addr(&self) -> Option<SocketAddrV4> { |
| 448 | + self.bitcoind.params.p2p_socket |
| 449 | + } |
442 | 450 | } |
443 | 451 |
|
444 | 452 | impl Drop for TestEnv { |
|
0 commit comments