|
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, BitcoindSyncClientConfig, Config, |
| 10 | + default_user_config, may_announce_channel, AnnounceError, BitcoindRestSyncClientConfig, Config, |
11 | 11 | ElectrumSyncConfig, EsploraSyncConfig, DEFAULT_LOG_FILENAME, DEFAULT_LOG_LEVEL,
|
12 | 12 | WALLET_KEYS_SEED_LEN,
|
13 | 13 | };
|
@@ -96,7 +96,7 @@ enum ChainDataSourceConfig {
|
96 | 96 | rpc_port: u16,
|
97 | 97 | rpc_user: String,
|
98 | 98 | rpc_password: String,
|
99 |
| - sync_client_config: BitcoindSyncClientConfig, |
| 99 | + sync_client_config: Option<BitcoindRestSyncClientConfig>, |
100 | 100 | },
|
101 | 101 | }
|
102 | 102 |
|
@@ -310,29 +310,70 @@ impl NodeBuilder {
|
310 | 310 | self
|
311 | 311 | }
|
312 | 312 |
|
313 |
| - /// Configures the [`Node`] instance to synchronize its chain data from the given Bitcoin Core RPC |
314 |
| - /// endpoint. |
| 313 | + /// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC. |
315 | 314 | ///
|
316 |
| - /// This method configures an RPC connection for essential operations, with options for |
317 |
| - /// synchronization via either RPC (default) or REST. |
| 315 | + /// This method establishes an RPC connection that enables all essential chain operations including |
| 316 | + /// transaction broadcasting and chain data synchronization. RPC is the minimum required configuration |
| 317 | + /// for Bitcoin Core chain interaction and must be set up before any other Bitcoin Core connection options. |
318 | 318 | ///
|
319 |
| - /// # Parameters: |
320 |
| - /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC connection |
321 |
| - /// * `sync_client_config` - Optional synchronization client configuration; defaults to using RPC for sync |
322 |
| - pub fn set_chain_source_bitcoind( |
| 319 | + /// ## Parameters: |
| 320 | + /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC |
| 321 | + /// connection. |
| 322 | + pub fn set_chain_source_bitcoind_rpc( |
323 | 323 | &mut self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
|
324 |
| - sync_client_config: Option<BitcoindSyncClientConfig>, |
325 | 324 | ) -> &mut Self {
|
326 | 325 | self.chain_data_source_config = Some(ChainDataSourceConfig::Bitcoind {
|
327 | 326 | rpc_host,
|
328 | 327 | rpc_port,
|
329 | 328 | rpc_user,
|
330 | 329 | rpc_password,
|
331 |
| - sync_client_config: sync_client_config.unwrap_or(BitcoindSyncClientConfig::Rpc), |
| 330 | + sync_client_config: None, |
332 | 331 | });
|
333 | 332 | self
|
334 | 333 | }
|
335 | 334 |
|
| 335 | + /// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint. |
| 336 | + /// |
| 337 | + /// This method enables chain data synchronization via Bitcoin Core's REST interface. |
| 338 | + /// It must be called after [`Self::set_chain_source_bitcoind_rpc`] because REST is used only for chain |
| 339 | + /// synchronization, while RPC is still required for other essential operations like transaction |
| 340 | + /// broadcasting. |
| 341 | + /// |
| 342 | + /// ## Parameters: |
| 343 | + /// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection. |
| 344 | + pub fn set_chain_source_bitcoind_rest( |
| 345 | + &mut self, rest_host: String, rest_port: u16, |
| 346 | + ) -> &mut Self { |
| 347 | + let rest_client_config = BitcoindRestSyncClientConfig { rest_host, rest_port }; |
| 348 | + |
| 349 | + match &mut self.chain_data_source_config { |
| 350 | + Some(ChainDataSourceConfig::Bitcoind { |
| 351 | + rpc_host, |
| 352 | + rpc_port, |
| 353 | + rpc_user, |
| 354 | + rpc_password, |
| 355 | + sync_client_config, |
| 356 | + }) => { |
| 357 | + if rpc_host.is_empty() |
| 358 | + || *rpc_port == 0 |
| 359 | + || rpc_user.is_empty() |
| 360 | + || rpc_password.is_empty() |
| 361 | + { |
| 362 | + panic!("RPC configuration is incomplete. Must fully configure via RPC first."); |
| 363 | + } |
| 364 | + |
| 365 | + *sync_client_config = Some(rest_client_config); |
| 366 | + }, |
| 367 | + Some(cs) => { |
| 368 | + panic!("This option is only valid for ChainSource::Bitcoind. Current chain source config: {cs:?}") |
| 369 | + }, |
| 370 | + None => { |
| 371 | + panic!("Must configure via RPC first.") |
| 372 | + }, |
| 373 | + } |
| 374 | + |
| 375 | + self |
| 376 | + } |
336 | 377 | /// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
|
337 | 378 | /// network.
|
338 | 379 | pub fn set_gossip_source_p2p(&mut self) -> &mut Self {
|
@@ -740,21 +781,39 @@ impl ArcedNodeBuilder {
|
740 | 781 | self.inner.write().unwrap().set_chain_source_electrum(server_url, sync_config);
|
741 | 782 | }
|
742 | 783 |
|
743 |
| - /// Configures the [`Node`] instance to source its chain data from the given Bitcoin Core RPC |
744 |
| - /// endpoint. |
745 |
| - pub fn set_chain_source_bitcoind( |
| 784 | + /// Configures the [`Node`] instance to connect to a Bitcoin Core node via RPC. |
| 785 | + /// |
| 786 | + /// This method establishes an RPC connection that enables all essential chain operations including |
| 787 | + /// transaction broadcasting and chain data synchronization. RPC is the minimum required configuration |
| 788 | + /// for Bitcoin Core chain interactions and must be set up before any other Bitcoin Core connection options. |
| 789 | + /// |
| 790 | + /// ## Parameters: |
| 791 | + /// * `rpc_host`, `rpc_port`, `rpc_user`, `rpc_password` - Required parameters for the Bitcoin Core RPC |
| 792 | + /// connection. |
| 793 | + pub fn set_chain_source_bitcoind_rpc( |
746 | 794 | &self, rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
|
747 |
| - sync_client_config: Option<BitcoindSyncClientConfig>, |
748 | 795 | ) {
|
749 |
| - self.inner.write().unwrap().set_chain_source_bitcoind( |
| 796 | + self.inner.write().unwrap().set_chain_source_bitcoind_rpc( |
750 | 797 | rpc_host,
|
751 | 798 | rpc_port,
|
752 | 799 | rpc_user,
|
753 | 800 | rpc_password,
|
754 |
| - sync_client_config, |
755 | 801 | );
|
756 | 802 | }
|
757 | 803 |
|
| 804 | + /// Configures the [`Node`] instance to synchronize chain data from a Bitcoin Core REST endpoint. |
| 805 | + /// |
| 806 | + /// This method enables chain data synchronization via Bitcoin Core's REST interface. |
| 807 | + /// It must be called after [`set_chain_source_bitcoind_rpc`] because REST is used only for chain |
| 808 | + /// synchronization, while RPC is still required for other essential operations like transaction |
| 809 | + /// broadcasting. |
| 810 | + /// |
| 811 | + /// ## Parameters: |
| 812 | + /// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection. |
| 813 | + pub fn set_chain_source_bitcoind_rest(&self, rest_host: String, rest_port: u16) { |
| 814 | + self.inner.write().unwrap().set_chain_source_bitcoind_rest(rest_host, rest_port); |
| 815 | + } |
| 816 | + |
758 | 817 | /// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
|
759 | 818 | /// network.
|
760 | 819 | pub fn set_gossip_source_p2p(&self) {
|
|
0 commit comments