Skip to content

Commit cd0ae98

Browse files
Implement Deref<Target=UrlClient> for EsploraBlockchain
There is currently no way to access the client from the EsploraBlockchain. This makes it difficult for users to extend it's functionality. This PR exposes both the reqwest and ureq clients. This PR is related to PR bitcoindevkit#705.
1 parent 9f9ffd0 commit cd0ae98

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/blockchain/esplora/reqwest.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::error::Error;
3232
use crate::FeeRate;
3333

3434
#[derive(Debug)]
35-
struct UrlClient {
35+
pub struct UrlClient {
3636
url: String,
3737
// We use the async client instead of the blocking one because it automatically uses `fetch`
3838
// when the target platform is wasm32.
@@ -46,6 +46,7 @@ struct UrlClient {
4646
/// See the [`blockchain::esplora`](crate::blockchain::esplora) module for a usage example.
4747
#[derive(Debug)]
4848
pub struct EsploraBlockchain {
49+
/// Esplora reqwest client
4950
url_client: UrlClient,
5051
stop_gap: usize,
5152
}
@@ -101,6 +102,14 @@ impl Blockchain for EsploraBlockchain {
101102
}
102103
}
103104

105+
impl Deref for EsploraBlockchain {
106+
type Target = UrlClient;
107+
108+
fn deref(&self) -> &Self::Target {
109+
&self.url_client
110+
}
111+
}
112+
104113
impl StatelessBlockchain for EsploraBlockchain {}
105114

106115
#[maybe_async]

src/blockchain/esplora/ureq.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::error::Error;
3434
use crate::FeeRate;
3535

3636
#[derive(Debug, Clone)]
37-
struct UrlClient {
37+
pub struct UrlClient {
3838
url: String,
3939
agent: Agent,
4040
}
@@ -45,6 +45,7 @@ struct UrlClient {
4545
/// See the [`blockchain::esplora`](crate::blockchain::esplora) module for a usage example.
4646
#[derive(Debug)]
4747
pub struct EsploraBlockchain {
48+
/// Esplora ureq client
4849
url_client: UrlClient,
4950
stop_gap: usize,
5051
concurrency: u8,
@@ -98,6 +99,14 @@ impl Blockchain for EsploraBlockchain {
9899
}
99100
}
100101

102+
impl Deref for EsploraBlockchain {
103+
type Target = UrlClient;
104+
105+
fn deref(&self) -> &Self::Target {
106+
&self.url_client
107+
}
108+
}
109+
101110
impl StatelessBlockchain for EsploraBlockchain {}
102111

103112
impl GetHeight for EsploraBlockchain {

0 commit comments

Comments
 (0)