77
88use crate :: chain:: { ChainSource , DEFAULT_ESPLORA_SERVER_URL } ;
99use crate :: config:: {
10- default_user_config, may_announce_channel, AnnounceError , Config , ElectrumSyncConfig ,
11- EsploraSyncConfig , DEFAULT_LOG_FILENAME , DEFAULT_LOG_LEVEL , WALLET_KEYS_SEED_LEN ,
10+ default_user_config, may_announce_channel, AnnounceError , BitcoindRestClientConfig , Config ,
11+ ElectrumSyncConfig , EsploraSyncConfig , DEFAULT_LOG_FILENAME , DEFAULT_LOG_LEVEL ,
12+ WALLET_KEYS_SEED_LEN ,
1213} ;
1314
1415use crate :: connection:: ConnectionManager ;
@@ -84,9 +85,21 @@ const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
8485
8586#[ derive( Debug , Clone ) ]
8687enum ChainDataSourceConfig {
87- Esplora { server_url : String , sync_config : Option < EsploraSyncConfig > } ,
88- Electrum { server_url : String , sync_config : Option < ElectrumSyncConfig > } ,
89- BitcoindRpc { rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String } ,
88+ Esplora {
89+ server_url : String ,
90+ sync_config : Option < EsploraSyncConfig > ,
91+ } ,
92+ Electrum {
93+ server_url : String ,
94+ sync_config : Option < ElectrumSyncConfig > ,
95+ } ,
96+ Bitcoind {
97+ rpc_host : String ,
98+ rpc_port : u16 ,
99+ rpc_user : String ,
100+ rpc_password : String ,
101+ rest_client_config : Option < BitcoindRestClientConfig > ,
102+ } ,
90103}
91104
92105#[ derive( Debug , Clone ) ]
@@ -299,13 +312,48 @@ impl NodeBuilder {
299312 self
300313 }
301314
302- /// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC
303- /// endpoint.
315+ /// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC.
316+ ///
317+ /// This method establishes an RPC connection that enables all essential chain operations including
318+ /// transaction broadcasting and chain data synchronization.
319+ ///
320+ /// ## Parameters:
321+ /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC
322+ /// connection.
304323 pub fn set_chain_source_bitcoind_rpc (
305324 & mut self , rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String ,
306325 ) -> & mut Self {
307- self . chain_data_source_config =
308- Some ( ChainDataSourceConfig :: BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password } ) ;
326+ self . chain_data_source_config = Some ( ChainDataSourceConfig :: Bitcoind {
327+ rpc_host,
328+ rpc_port,
329+ rpc_user,
330+ rpc_password,
331+ rest_client_config : None ,
332+ } ) ;
333+ self
334+ }
335+
336+ /// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint.
337+ ///
338+ /// This method enables chain data synchronization via Bitcoin Core's REST interface. We pass
339+ /// additional RPC configuration to non-REST-supported API calls like transaction broadcasting.
340+ ///
341+ /// ## Parameters:
342+ /// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection.
343+ /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC
344+ /// connection
345+ pub fn set_chain_source_bitcoind_rest (
346+ & mut self , rest_host : String , rest_port : u16 , rpc_host : String , rpc_port : u16 ,
347+ rpc_user : String , rpc_password : String ,
348+ ) -> & mut Self {
349+ self . chain_data_source_config = Some ( ChainDataSourceConfig :: Bitcoind {
350+ rpc_host,
351+ rpc_port,
352+ rpc_user,
353+ rpc_password,
354+ rest_client_config : Some ( BitcoindRestClientConfig { rest_host, rest_port } ) ,
355+ } ) ;
356+
309357 self
310358 }
311359
@@ -716,8 +764,14 @@ impl ArcedNodeBuilder {
716764 self . inner . write ( ) . unwrap ( ) . set_chain_source_electrum ( server_url, sync_config) ;
717765 }
718766
719- /// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC
720- /// endpoint.
767+ /// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC.
768+ ///
769+ /// This method establishes an RPC connection that enables all essential chain operations including
770+ /// transaction broadcasting and chain data synchronization.
771+ ///
772+ /// ## Parameters:
773+ /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC
774+ /// connection.
721775 pub fn set_chain_source_bitcoind_rpc (
722776 & self , rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String ,
723777 ) {
@@ -729,6 +783,29 @@ impl ArcedNodeBuilder {
729783 ) ;
730784 }
731785
786+ /// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint.
787+ ///
788+ /// This method enables chain data synchronization via Bitcoin Core's REST interface. We pass
789+ /// additional RPC configuration to non-REST-supported API calls like transaction broadcasting.
790+ ///
791+ /// ## Parameters:
792+ /// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection.
793+ /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC
794+ /// connection
795+ pub fn set_chain_source_bitcoind_rest (
796+ & self , rest_host : String , rest_port : u16 , rpc_host : String , rpc_port : u16 ,
797+ rpc_user : String , rpc_password : String ,
798+ ) {
799+ self . inner . write ( ) . unwrap ( ) . set_chain_source_bitcoind_rest (
800+ rest_host,
801+ rest_port,
802+ rpc_host,
803+ rpc_port,
804+ rpc_user,
805+ rpc_password,
806+ ) ;
807+ }
808+
732809 /// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
733810 /// network.
734811 pub fn set_gossip_source_p2p ( & self ) {
@@ -1068,8 +1145,14 @@ fn build_with_store_internal(
10681145 Arc :: clone ( & node_metrics) ,
10691146 ) )
10701147 } ,
1071- Some ( ChainDataSourceConfig :: BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password } ) => {
1072- Arc :: new ( ChainSource :: new_bitcoind_rpc (
1148+ Some ( ChainDataSourceConfig :: Bitcoind {
1149+ rpc_host,
1150+ rpc_port,
1151+ rpc_user,
1152+ rpc_password,
1153+ rest_client_config,
1154+ } ) => match rest_client_config {
1155+ Some ( rest_client_config) => Arc :: new ( ChainSource :: new_bitcoind_rest (
10731156 rpc_host. clone ( ) ,
10741157 * rpc_port,
10751158 rpc_user. clone ( ) ,
@@ -1079,10 +1162,25 @@ fn build_with_store_internal(
10791162 Arc :: clone ( & tx_broadcaster) ,
10801163 Arc :: clone ( & kv_store) ,
10811164 Arc :: clone ( & config) ,
1165+ rest_client_config. clone ( ) ,
10821166 Arc :: clone ( & logger) ,
10831167 Arc :: clone ( & node_metrics) ,
1084- ) )
1168+ ) ) ,
1169+ None => Arc :: new ( ChainSource :: new_bitcoind_rpc (
1170+ rpc_host. clone ( ) ,
1171+ * rpc_port,
1172+ rpc_user. clone ( ) ,
1173+ rpc_password. clone ( ) ,
1174+ Arc :: clone ( & wallet) ,
1175+ Arc :: clone ( & fee_estimator) ,
1176+ Arc :: clone ( & tx_broadcaster) ,
1177+ Arc :: clone ( & kv_store) ,
1178+ Arc :: clone ( & config) ,
1179+ Arc :: clone ( & logger) ,
1180+ Arc :: clone ( & node_metrics) ,
1181+ ) ) ,
10851182 } ,
1183+
10861184 None => {
10871185 // Default to Esplora client.
10881186 let server_url = DEFAULT_ESPLORA_SERVER_URL . to_string ( ) ;
0 commit comments