Skip to content

Commit 0814b13

Browse files
committed
Allow to configure bitcoind RPC in Builder
1 parent 31b4da7 commit 0814b13

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

bindings/ldk_node.udl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface Builder {
3636
void set_entropy_seed_bytes(sequence<u8> seed_bytes);
3737
void set_entropy_bip39_mnemonic(Mnemonic mnemonic, string? passphrase);
3838
void set_chain_source_esplora(string server_url, EsploraSyncConfig? config);
39+
void set_chain_source_bitcoind_rpc(string rpc_host, u16 rpc_port, string rpc_user, string rpc_password);
3940
void set_gossip_source_p2p();
4041
void set_gossip_source_rgs(string rgs_server_url);
4142
void set_liquidity_source_lsps2(SocketAddress address, PublicKey node_id, string? token);

src/builder.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use std::time::SystemTime;
7878
#[derive(Debug, Clone)]
7979
enum ChainDataSourceConfig {
8080
Esplora { server_url: String, sync_config: Option<EsploraSyncConfig> },
81+
BitcoindRpc { rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String },
8182
}
8283

8384
#[derive(Debug, Clone)]
@@ -248,6 +249,16 @@ impl NodeBuilder {
248249
self
249250
}
250251

252+
/// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC
253+
/// endpoint.
254+
pub fn set_chain_source_bitcoind_rpc(
255+
&mut self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
256+
) -> &mut Self {
257+
self.chain_data_source_config =
258+
Some(ChainDataSourceConfig::BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password });
259+
self
260+
}
261+
251262
/// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
252263
/// network.
253264
pub fn set_gossip_source_p2p(&mut self) -> &mut Self {
@@ -479,6 +490,19 @@ impl ArcedNodeBuilder {
479490
self.inner.write().unwrap().set_chain_source_esplora(server_url, sync_config);
480491
}
481492

493+
/// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC
494+
/// endpoint.
495+
pub fn set_chain_source_bitcoind_rpc(
496+
&self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
497+
) {
498+
self.inner.write().unwrap().set_chain_source_bitcoind_rpc(
499+
rpc_host,
500+
rpc_port,
501+
rpc_user,
502+
rpc_password,
503+
);
504+
}
505+
482506
/// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
483507
/// network.
484508
pub fn set_gossip_source_p2p(&self) {
@@ -633,6 +657,21 @@ fn build_with_store_internal(
633657
Arc::clone(&node_metrics),
634658
))
635659
},
660+
Some(ChainDataSourceConfig::BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password }) => {
661+
Arc::new(ChainSource::new_bitcoind_rpc(
662+
rpc_host.clone(),
663+
*rpc_port,
664+
rpc_user.clone(),
665+
rpc_password.clone(),
666+
Arc::clone(&wallet),
667+
Arc::clone(&fee_estimator),
668+
Arc::clone(&tx_broadcaster),
669+
Arc::clone(&kv_store),
670+
Arc::clone(&config),
671+
Arc::clone(&logger),
672+
Arc::clone(&node_metrics),
673+
))
674+
},
636675
None => {
637676
// Default to Esplora client.
638677
let server_url = DEFAULT_ESPLORA_SERVER_URL.to_string();

0 commit comments

Comments
 (0)