@@ -185,6 +185,17 @@ pub enum BuildError {
185
185
LoggerSetupFailed ,
186
186
/// The given network does not match the node's previously configured network.
187
187
NetworkMismatch ,
188
+ /// The RPC configuration for [`ChainSource::Bitcoind`] 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 a different type).
198
+ InvalidChainSourceConfig ,
188
199
}
189
200
190
201
impl fmt:: Display for BuildError {
@@ -212,6 +223,12 @@ impl fmt::Display for BuildError {
212
223
Self :: NetworkMismatch => {
213
224
write ! ( f, "Given network does not match the node's previously configured network." )
214
225
} ,
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
+ } ,
215
232
}
216
233
}
217
234
}
@@ -343,7 +360,7 @@ impl NodeBuilder {
343
360
/// * `rest_host`, `rest_port` - Required parameters for the Bitcoin Core REST connection.
344
361
pub fn set_chain_source_bitcoind_rest (
345
362
& mut self , rest_host : String , rest_port : u16 ,
346
- ) -> & mut Self {
363
+ ) -> Result < & mut Self , BuildError > {
347
364
let rest_client_config = BitcoindRestSyncClientConfig { rest_host, rest_port } ;
348
365
349
366
match & mut self . chain_data_source_config {
@@ -359,20 +376,22 @@ impl NodeBuilder {
359
376
|| rpc_user. is_empty ( )
360
377
|| rpc_password. is_empty ( )
361
378
{
362
- panic ! ( "RPC configuration is incomplete. Must fully configure via RPC first." ) ;
379
+ return Err ( BuildError :: MissingBitcoindRpcConfig ) ;
363
380
}
364
381
365
382
* sync_client_config = Some ( rest_client_config) ;
366
383
} ,
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 ) ;
369
387
} ,
370
388
None => {
371
- panic ! ( "Must configure via RPC first." )
389
+ // Must configure via RPC first.
390
+ return Err ( BuildError :: MissingBitcoindRpcConfig ) ;
372
391
} ,
373
392
}
374
393
375
- self
394
+ Ok ( self )
376
395
}
377
396
/// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
378
397
/// network.
@@ -810,8 +829,10 @@ impl ArcedNodeBuilder {
810
829
///
811
830
/// ## Parameters:
812
831
/// * `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 ( |_| ( ) )
815
836
}
816
837
817
838
/// Configures the [`Node`] instance to source its gossip data from the Lightning peer-to-peer
0 commit comments