Skip to content

Commit

Permalink
feat(btcio): make BitcoinClient Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Feb 7, 2025
1 parent 507184c commit 3d67d9d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions crates/btcio/src/rpc/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::{
env::var,
fmt,
sync::atomic::{AtomicUsize, Ordering},
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
},
time::Duration,
};

Expand Down Expand Up @@ -54,14 +57,18 @@ where
}

/// An `async` client for interacting with a `bitcoind` instance.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct BitcoinClient {
/// The URL of the `bitcoind` instance.
url: String,
/// The underlying `async` HTTP client.
client: Client,
/// The ID of the current request.
id: AtomicUsize,
///
/// # Implementation Details
///
/// Using an [`Arc`] so that [BitcoinClient] is [`Clone`].
id: Arc<AtomicUsize>,
/// The maximum number of retries for a request.
max_retries: u8,
/// Interval between retries for a request in ms.
Expand Down Expand Up @@ -107,7 +114,7 @@ impl BitcoinClient {
.build()
.map_err(|e| ClientError::Other(format!("Could not create client: {e}")))?;

let id = AtomicUsize::new(0);
let id = Arc::new(AtomicUsize::new(0));

let max_retries = max_retries.unwrap_or(DEFAULT_MAX_RETRIES);
let retry_interval = retry_interval.unwrap_or(DEFAULT_RETRY_INTERVAL_MS);
Expand Down

0 comments on commit 3d67d9d

Please sign in to comment.