@@ -330,6 +330,9 @@ pub struct BitcoinRpcClient {
330
330
/// Represents errors that can occur when using [`BitcoinRpcClient`].
331
331
#[ derive( Debug , thiserror:: Error ) ]
332
332
pub enum BitcoinRpcClientError {
333
+ // Missing credential error
334
+ #[ error( "Missing credential error" ) ]
335
+ MissingCredentials ,
333
336
// RPC Transport errors
334
337
#[ error( "Rcp error: {0}" ) ]
335
338
Rpc ( #[ from] RpcError ) ,
@@ -346,10 +349,9 @@ pub type BitcoinRpcClientResult<T> = Result<T, BitcoinRpcClientError>;
346
349
347
350
impl BitcoinRpcClient {
348
351
/// Create a [`BitcoinRpcClient`] from Stacks Configuration, mainly using [`stacks::config::BurnchainConfig`]
349
- pub fn from_stx_config ( config : & Config ) -> Result < Self , String > {
352
+ pub fn from_stx_config ( config : & Config ) -> BitcoinRpcClientResult < Self > {
350
353
let host = config. burnchain . peer_host . clone ( ) ;
351
354
let port = config. burnchain . rpc_port ;
352
- let ssl = config. burnchain . rpc_ssl ;
353
355
let username_opt = & config. burnchain . username ;
354
356
let password_opt = & config. burnchain . password ;
355
357
let wallet_name = config. burnchain . wallet_name . clone ( ) ;
@@ -361,10 +363,10 @@ impl BitcoinRpcClient {
361
363
username : username. clone ( ) ,
362
364
password : password. clone ( ) ,
363
365
} ,
364
- _ => return Err ( "Missing RPC credentials!" . to_string ( ) ) ,
366
+ _ => return Err ( BitcoinRpcClientError :: MissingCredentials ) ,
365
367
} ;
366
368
367
- Self :: new ( host, port, ssl , rpc_auth, wallet_name, timeout, client_id)
369
+ Self :: new ( host, port, rpc_auth, wallet_name, timeout, client_id)
368
370
}
369
371
370
372
/// Creates a new instance of the Bitcoin RPC client with both global and wallet-specific endpoints.
@@ -373,7 +375,6 @@ impl BitcoinRpcClient {
373
375
///
374
376
/// * `host` - Hostname or IP address of the Bitcoin RPC server (e.g., `localhost`).
375
377
/// * `port` - Port number the RPC server is listening on.
376
- /// * `ssl` - If `true`, uses HTTPS for communication; otherwise, uses HTTP.
377
378
/// * `auth` - RPC authentication credentials (`RpcAuth::None` or `RpcAuth::Basic`).
378
379
/// * `wallet_name` - Name of the wallet to target for wallet-specific RPC calls.
379
380
/// * `timeout` - Timeout for RPC requests, in seconds.
@@ -386,24 +387,20 @@ impl BitcoinRpcClient {
386
387
pub fn new (
387
388
host : String ,
388
389
port : u16 ,
389
- ssl : bool ,
390
390
auth : RpcAuth ,
391
391
wallet_name : String ,
392
392
timeout : u32 ,
393
393
client_id : String ,
394
- ) -> Result < Self , String > {
395
- let protocol = if ssl { "https" } else { "http" } ;
396
- let rpc_global_path = format ! ( "{protocol}://{host}:{port}" ) ;
394
+ ) -> BitcoinRpcClientResult < Self > {
395
+ let rpc_global_path = format ! ( "http://{host}:{port}" ) ;
397
396
let rpc_wallet_path = format ! ( "{rpc_global_path}/wallet/{wallet_name}" ) ;
398
397
let rpc_auth = auth;
399
398
400
399
let rpc_timeout = Duration :: from_secs ( u64:: from ( timeout) ) ;
401
400
402
401
let global_ep =
403
- RpcTransport :: new ( rpc_global_path, rpc_auth. clone ( ) , Some ( rpc_timeout. clone ( ) ) )
404
- . map_err ( |e| format ! ( "Failed to create global RpcTransport: {e:?}" ) ) ?;
405
- let wallet_ep = RpcTransport :: new ( rpc_wallet_path, rpc_auth, Some ( rpc_timeout) )
406
- . map_err ( |e| format ! ( "Failed to create wallet RpcTransport: {e:?}" ) ) ?;
402
+ RpcTransport :: new ( rpc_global_path, rpc_auth. clone ( ) , Some ( rpc_timeout. clone ( ) ) ) ?;
403
+ let wallet_ep = RpcTransport :: new ( rpc_wallet_path, rpc_auth, Some ( rpc_timeout) ) ?;
407
404
408
405
Ok ( Self {
409
406
client_id,
0 commit comments