7
7
8
8
use crate :: chain:: { ChainSource , DEFAULT_ESPLORA_SERVER_URL } ;
9
9
use 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 ,
12
13
} ;
13
14
14
15
use crate :: connection:: ConnectionManager ;
@@ -84,9 +85,21 @@ const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
84
85
85
86
#[ derive( Debug , Clone ) ]
86
87
enum 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
+ } ,
90
103
}
91
104
92
105
#[ derive( Debug , Clone ) ]
@@ -299,13 +312,48 @@ impl NodeBuilder {
299
312
self
300
313
}
301
314
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.
304
323
pub fn set_chain_source_bitcoind_rpc (
305
324
& mut self , rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String ,
306
325
) -> & 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
+
309
357
self
310
358
}
311
359
@@ -716,8 +764,14 @@ impl ArcedNodeBuilder {
716
764
self . inner . write ( ) . unwrap ( ) . set_chain_source_electrum ( server_url, sync_config) ;
717
765
}
718
766
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.
721
775
pub fn set_chain_source_bitcoind_rpc (
722
776
& self , rpc_host : String , rpc_port : u16 , rpc_user : String , rpc_password : String ,
723
777
) {
@@ -729,6 +783,29 @@ impl ArcedNodeBuilder {
729
783
) ;
730
784
}
731
785
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
+
732
809
/// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
733
810
/// network.
734
811
pub fn set_gossip_source_p2p ( & self ) {
@@ -1068,8 +1145,14 @@ fn build_with_store_internal(
1068
1145
Arc :: clone ( & node_metrics) ,
1069
1146
) )
1070
1147
} ,
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 (
1073
1156
rpc_host. clone ( ) ,
1074
1157
* rpc_port,
1075
1158
rpc_user. clone ( ) ,
@@ -1079,10 +1162,25 @@ fn build_with_store_internal(
1079
1162
Arc :: clone ( & tx_broadcaster) ,
1080
1163
Arc :: clone ( & kv_store) ,
1081
1164
Arc :: clone ( & config) ,
1165
+ rest_client_config. clone ( ) ,
1082
1166
Arc :: clone ( & logger) ,
1083
1167
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
+ ) ) ,
1085
1182
} ,
1183
+
1086
1184
None => {
1087
1185
// Default to Esplora client.
1088
1186
let server_url = DEFAULT_ESPLORA_SERVER_URL . to_string ( ) ;
0 commit comments