@@ -185,6 +185,17 @@ pub enum BuildError {
185185 LoggerSetupFailed ,
186186 /// The given network does not match the node's previously configured network.
187187 NetworkMismatch ,
188+ /// The RPC configuration for Bitcoin Core is incomplete or missing.
189+ ///
190+ /// This error occurs in two scenarios:
191+ /// 1. When the RPC configuration fields (host, port, user, password) are empty or invalid.
192+ /// 2. When attempting to configure REST synchronization before setting up RPC configuration.
193+ MissingBitcoindRpcConfig ,
194+ /// Invalid chain source configuration.
195+ ///
196+ /// This error occurs when attempting to set Bitcoin Core REST configuration on a non-Bitcoind
197+ /// chain source (such as when the chain source is already configured for Esplora/Electrum).
198+ InvalidChainSourceConfig ,
188199}
189200
190201impl fmt:: Display for BuildError {
@@ -212,6 +223,12 @@ impl fmt::Display for BuildError {
212223 Self :: NetworkMismatch => {
213224 write ! ( f, "Given network does not match the node's previously configured network." )
214225 } ,
226+ Self :: MissingBitcoindRpcConfig => {
227+ write ! ( f, "Failed to configure RPC client for ChainSource::Bitcoind." )
228+ } ,
229+ Self :: InvalidChainSourceConfig => {
230+ write ! ( f, "Given REST client configuration is invalid for the ChainSource variant." )
231+ } ,
215232 }
216233 }
217234}
@@ -343,7 +360,7 @@ impl NodeBuilder {
343360 /// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection.
344361 pub fn set_chain_source_bitcoind_rest (
345362 & mut self , rest_host : String , rest_port : u16 ,
346- ) -> & mut Self {
363+ ) -> Result < & mut Self , BuildError > {
347364 let rest_client_config = BitcoindRestSyncClientConfig { rest_host, rest_port } ;
348365
349366 match & mut self . chain_data_source_config {
@@ -359,20 +376,22 @@ impl NodeBuilder {
359376 || rpc_user. is_empty ( )
360377 || rpc_password. is_empty ( )
361378 {
362- panic ! ( "RPC configuration is incomplete. Must fully configure via RPC first." ) ;
379+ return Err ( BuildError :: MissingBitcoindRpcConfig ) ;
363380 }
364381
365382 * sync_client_config = Some ( rest_client_config) ;
366383 } ,
367- Some ( cs) => {
368- panic ! ( "This option is only valid for ChainSource::Bitcoind. Current chain source config: {cs:?}" )
384+ Some ( _) => {
385+ // This option is only valid for ChainSource::Bitcoind.
386+ return Err ( BuildError :: InvalidChainSourceConfig ) ;
369387 } ,
370388 None => {
371- panic ! ( "Must configure via RPC first." )
389+ // Must configure via RPC first.
390+ return Err ( BuildError :: MissingBitcoindRpcConfig ) ;
372391 } ,
373392 }
374393
375- self
394+ Ok ( self )
376395 }
377396 /// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
378397 /// network.
@@ -810,8 +829,10 @@ impl ArcedNodeBuilder {
810829 ///
811830 /// ## Parameters:
812831 /// * `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) ;
832+ pub fn set_chain_source_bitcoind_rest (
833+ & self , rest_host : String , rest_port : u16 ,
834+ ) -> Result < ( ) , BuildError > {
835+ self . inner . write ( ) . unwrap ( ) . set_chain_source_bitcoind_rest ( rest_host, rest_port) . map ( |_| ( ) )
815836 }
816837
817838 /// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
0 commit comments