Skip to content

Commit 59a247f

Browse files
committed
crc: remove ssl argument + improve BitcoinRpcClientError, #6250
1 parent 791bd39 commit 59a247f

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

stacks-node/src/burnchains/rpc/bitcoin_rpc_client/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ pub struct BitcoinRpcClient {
330330
/// Represents errors that can occur when using [`BitcoinRpcClient`].
331331
#[derive(Debug, thiserror::Error)]
332332
pub enum BitcoinRpcClientError {
333+
// Missing credential error
334+
#[error("Missing credential error")]
335+
MissingCredentials,
333336
// RPC Transport errors
334337
#[error("Rcp error: {0}")]
335338
Rpc(#[from] RpcError),
@@ -346,10 +349,9 @@ pub type BitcoinRpcClientResult<T> = Result<T, BitcoinRpcClientError>;
346349

347350
impl BitcoinRpcClient {
348351
/// 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> {
350353
let host = config.burnchain.peer_host.clone();
351354
let port = config.burnchain.rpc_port;
352-
let ssl = config.burnchain.rpc_ssl;
353355
let username_opt = &config.burnchain.username;
354356
let password_opt = &config.burnchain.password;
355357
let wallet_name = config.burnchain.wallet_name.clone();
@@ -361,10 +363,10 @@ impl BitcoinRpcClient {
361363
username: username.clone(),
362364
password: password.clone(),
363365
},
364-
_ => return Err("Missing RPC credentials!".to_string()),
366+
_ => return Err(BitcoinRpcClientError::MissingCredentials),
365367
};
366368

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)
368370
}
369371

370372
/// Creates a new instance of the Bitcoin RPC client with both global and wallet-specific endpoints.
@@ -373,7 +375,6 @@ impl BitcoinRpcClient {
373375
///
374376
/// * `host` - Hostname or IP address of the Bitcoin RPC server (e.g., `localhost`).
375377
/// * `port` - Port number the RPC server is listening on.
376-
/// * `ssl` - If `true`, uses HTTPS for communication; otherwise, uses HTTP.
377378
/// * `auth` - RPC authentication credentials (`RpcAuth::None` or `RpcAuth::Basic`).
378379
/// * `wallet_name` - Name of the wallet to target for wallet-specific RPC calls.
379380
/// * `timeout` - Timeout for RPC requests, in seconds.
@@ -386,24 +387,20 @@ impl BitcoinRpcClient {
386387
pub fn new(
387388
host: String,
388389
port: u16,
389-
ssl: bool,
390390
auth: RpcAuth,
391391
wallet_name: String,
392392
timeout: u32,
393393
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}");
397396
let rpc_wallet_path = format!("{rpc_global_path}/wallet/{wallet_name}");
398397
let rpc_auth = auth;
399398

400399
let rpc_timeout = Duration::from_secs(u64::from(timeout));
401400

402401
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))?;
407404

408405
Ok(Self {
409406
client_id,

stacks-node/src/burnchains/rpc/bitcoin_rpc_client/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ mod utils {
4444
BitcoinRpcClient::new(
4545
parsed.host_str().unwrap().to_string(),
4646
parsed.port_or_known_default().unwrap(),
47-
parsed.scheme() == "https",
4847
RpcAuth::None,
4948
"mywallet".into(),
5049
30,

stacks-node/src/tests/bitcoin_rpc_integrations.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ mod utils {
6868
BitcoinRpcClient::new(
6969
config.burnchain.peer_host,
7070
config.burnchain.rpc_port,
71-
config.burnchain.rpc_ssl,
7271
RpcAuth::None,
7372
config.burnchain.wallet_name,
7473
config.burnchain.timeout,
@@ -141,7 +140,7 @@ fn test_client_creation_fails_due_to_stx_config_missing_auth() {
141140

142141
let err = BitcoinRpcClient::from_stx_config(&config_no_auth).expect_err("Client should fail!");
143142

144-
assert_eq!("Missing RPC credentials!", err);
143+
assert!(matches!(err, BitcoinRpcClientError::MissingCredentials));
145144
}
146145

147146
#[ignore]

0 commit comments

Comments
 (0)