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,15 @@ 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. RPC is the minimum required configuration
771+ /// for Bitcoin Core chain interactions and must be set up before any other Bitcoin Core connection options.
772+ ///
773+ /// ## Parameters:
774+ /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC
775+ /// connection.
721776 pub fn set_chain_source_bitcoind_rpc (
722777 & self , rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String ,
723778 ) {
@@ -729,6 +784,29 @@ impl ArcedNodeBuilder {
729784 ) ;
730785 }
731786
787+ /// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint.
788+ ///
789+ /// This method enables chain data synchronization via Bitcoin Core's REST interface.
790+ /// It must be called after [`set_chain_source_bitcoind_rpc`] because REST is used only for chain
791+ /// synchronization, while RPC is still required for other essential operations like transaction
792+ /// broadcasting.
793+ ///
794+ /// ## Parameters:
795+ /// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection.
796+ pub fn set_chain_source_bitcoind_rest (
797+ & self , rest_host : String , rest_port : u16 , rpc_host : String , rpc_port : u16 ,
798+ rpc_user : String , rpc_password : String ,
799+ ) {
800+ self . inner . write ( ) . unwrap ( ) . set_chain_source_bitcoind_rest (
801+ rest_host,
802+ rest_port,
803+ rpc_host,
804+ rpc_port,
805+ rpc_user,
806+ rpc_password,
807+ ) ;
808+ }
809+
732810 /// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
733811 /// network.
734812 pub fn set_gossip_source_p2p ( & self ) {
@@ -1068,8 +1146,14 @@ fn build_with_store_internal(
10681146 Arc :: clone ( & node_metrics) ,
10691147 ) )
10701148 } ,
1071- Some ( ChainDataSourceConfig :: BitcoindRpc { rpc_host, rpc_port, rpc_user, rpc_password } ) => {
1072- Arc :: new ( ChainSource :: new_bitcoind_rpc (
1149+ Some ( ChainDataSourceConfig :: Bitcoind {
1150+ rpc_host,
1151+ rpc_port,
1152+ rpc_user,
1153+ rpc_password,
1154+ rest_client_config,
1155+ } ) => match rest_client_config {
1156+ Some ( rest_client_config) => Arc :: new ( ChainSource :: new_bitcoind_rest (
10731157 rpc_host. clone ( ) ,
10741158 * rpc_port,
10751159 rpc_user. clone ( ) ,
@@ -1079,10 +1163,25 @@ fn build_with_store_internal(
10791163 Arc :: clone ( & tx_broadcaster) ,
10801164 Arc :: clone ( & kv_store) ,
10811165 Arc :: clone ( & config) ,
1166+ rest_client_config. clone ( ) ,
10821167 Arc :: clone ( & logger) ,
10831168 Arc :: clone ( & node_metrics) ,
1084- ) )
1169+ ) ) ,
1170+ None => Arc :: new ( ChainSource :: new_bitcoind_rpc (
1171+ rpc_host. clone ( ) ,
1172+ * rpc_port,
1173+ rpc_user. clone ( ) ,
1174+ rpc_password. clone ( ) ,
1175+ Arc :: clone ( & wallet) ,
1176+ Arc :: clone ( & fee_estimator) ,
1177+ Arc :: clone ( & tx_broadcaster) ,
1178+ Arc :: clone ( & kv_store) ,
1179+ Arc :: clone ( & config) ,
1180+ Arc :: clone ( & logger) ,
1181+ Arc :: clone ( & node_metrics) ,
1182+ ) ) ,
10851183 } ,
1184+
10861185 None => {
10871186 // Default to Esplora client.
10881187 let server_url = DEFAULT_ESPLORA_SERVER_URL . to_string ( ) ;
0 commit comments