Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
enum ChainDataSourceConfig {
Esplora {
server_url: String,
headers: HashMap<String, String>,
sync_config: Option<EsploraSyncConfig>,
},
Electrum {
Expand Down Expand Up @@ -294,9 +295,28 @@ impl NodeBuilder {
/// information.
pub fn set_chain_source_esplora(
&mut self, server_url: String, sync_config: Option<EsploraSyncConfig>,
) -> &mut Self {
self.chain_data_source_config = Some(ChainDataSourceConfig::Esplora {
server_url,
headers: Default::default(),
sync_config,
});
self
}

/// Configures the [`Node`] instance to source its chain data from the given Esplora server.
///
/// The given `headers` will be included in all requests to the Esplora server, typically used for
/// authentication purposes.
///
/// If no `sync_config` is given, default values are used. See [`EsploraSyncConfig`] for more
/// information.
pub fn set_chain_source_esplora_with_headers(
&mut self, server_url: String, headers: HashMap<String, String>,
sync_config: Option<EsploraSyncConfig>,
) -> &mut Self {
self.chain_data_source_config =
Some(ChainDataSourceConfig::Esplora { server_url, sync_config });
Some(ChainDataSourceConfig::Esplora { server_url, headers, sync_config });
self
}

Expand Down Expand Up @@ -754,6 +774,24 @@ impl ArcedNodeBuilder {
self.inner.write().unwrap().set_chain_source_esplora(server_url, sync_config);
}

/// Configures the [`Node`] instance to source its chain data from the given Esplora server.
///
/// The given `headers` will be included in all requests to the Esplora server, typically used for
/// authentication purposes.
///
/// If no `sync_config` is given, default values are used. See [`EsploraSyncConfig`] for more
/// information.
pub fn set_chain_source_esplora_with_headers(
&self, server_url: String, headers: HashMap<String, String>,
sync_config: Option<EsploraSyncConfig>,
) {
self.inner.write().unwrap().set_chain_source_esplora_with_headers(
server_url,
headers,
sync_config,
);
}

/// Configures the [`Node`] instance to source its chain data from the given Electrum server.
///
/// If no `sync_config` is given, default values are used. See [`ElectrumSyncConfig`] for more
Expand Down Expand Up @@ -1117,10 +1155,11 @@ fn build_with_store_internal(
));

let chain_source = match chain_data_source_config {
Some(ChainDataSourceConfig::Esplora { server_url, sync_config }) => {
Some(ChainDataSourceConfig::Esplora { server_url, headers, sync_config }) => {
let sync_config = sync_config.unwrap_or(EsploraSyncConfig::default());
Arc::new(ChainSource::new_esplora(
server_url.clone(),
headers.clone(),
sync_config,
Arc::clone(&wallet),
Arc::clone(&fee_estimator),
Expand Down Expand Up @@ -1187,6 +1226,7 @@ fn build_with_store_internal(
let sync_config = EsploraSyncConfig::default();
Arc::new(ChainSource::new_esplora(
server_url.clone(),
HashMap::new(),
sync_config,
Arc::clone(&wallet),
Arc::clone(&fee_estimator),
Expand Down
18 changes: 14 additions & 4 deletions src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,31 @@ pub(crate) enum ChainSource {

impl ChainSource {
pub(crate) fn new_esplora(
server_url: String, sync_config: EsploraSyncConfig, onchain_wallet: Arc<Wallet>,
fee_estimator: Arc<OnchainFeeEstimator>, tx_broadcaster: Arc<Broadcaster>,
kv_store: Arc<DynStore>, config: Arc<Config>, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
server_url: String, headers: HashMap<String, String>, sync_config: EsploraSyncConfig,
onchain_wallet: Arc<Wallet>, fee_estimator: Arc<OnchainFeeEstimator>,
tx_broadcaster: Arc<Broadcaster>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
) -> Self {
// FIXME / TODO: We introduced this to make `bdk_esplora` work separately without updating
// `lightning-transaction-sync`. We should revert this as part of of the upgrade to LDK 0.2.
let mut client_builder_0_11 = esplora_client_0_11::Builder::new(&server_url);
client_builder_0_11 = client_builder_0_11.timeout(DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS);

for (header_name, header_value) in &headers {
client_builder_0_11 = client_builder_0_11.header(header_name, header_value);
}

let esplora_client_0_11 = client_builder_0_11.build_async().unwrap();
let tx_sync =
Arc::new(EsploraSyncClient::from_client(esplora_client_0_11, Arc::clone(&logger)));

let mut client_builder = esplora_client::Builder::new(&server_url);
client_builder = client_builder.timeout(DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS);

for (header_name, header_value) in &headers {
client_builder = client_builder.header(header_name, header_value);
}

let esplora_client = client_builder.build_async().unwrap();

let onchain_wallet_sync_status = Mutex::new(WalletSyncStatus::Completed);
Expand Down
Loading