Skip to content

Commit a5d1a3d

Browse files
committed
Merge #722: Implement Deref<Target=UrlClient> for EsploraBlockchain
baf7eaa Implement Deref<Target=UrlClient> for EsploraBlockchain (Vladimir Fomene) Pull request description: ### Description 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 #705. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: rajarshimaitra: tACK baf7eaa Tree-SHA512: e2f530058c88e06fc2972edfcd2df1b534d43b0214d710b62e4d5200ac0e38dad6a9f8db1e0c7a7ed19892e59411dcc07f3f6dc8ad58afae9d677169ca98bb38
2 parents 7bc2980 + baf7eaa commit a5d1a3d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/blockchain/esplora/reqwest.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! Esplora by way of `reqwest` HTTP client.
1313
1414
use std::collections::{HashMap, HashSet};
15+
use std::ops::Deref;
1516

1617
use bitcoin::consensus::{deserialize, serialize};
1718
use bitcoin::hashes::hex::{FromHex, ToHex};
@@ -31,8 +32,9 @@ use crate::database::BatchDatabase;
3132
use crate::error::Error;
3233
use crate::FeeRate;
3334

35+
/// Structure encapsulates Esplora client
3436
#[derive(Debug)]
35-
struct UrlClient {
37+
pub struct UrlClient {
3638
url: String,
3739
// We use the async client instead of the blocking one because it automatically uses `fetch`
3840
// when the target platform is wasm32.
@@ -101,6 +103,14 @@ impl Blockchain for EsploraBlockchain {
101103
}
102104
}
103105

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

106116
#[maybe_async]

src/blockchain/esplora/ureq.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use std::collections::{HashMap, HashSet};
1515
use std::io;
1616
use std::io::Read;
17+
use std::ops::Deref;
1718
use std::time::Duration;
1819

1920
#[allow(unused_imports)]
@@ -33,8 +34,9 @@ use crate::database::BatchDatabase;
3334
use crate::error::Error;
3435
use crate::FeeRate;
3536

37+
/// Structure encapsulates ureq Esplora client
3638
#[derive(Debug, Clone)]
37-
struct UrlClient {
39+
pub struct UrlClient {
3840
url: String,
3941
agent: Agent,
4042
}
@@ -98,6 +100,14 @@ impl Blockchain for EsploraBlockchain {
98100
}
99101
}
100102

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

103113
impl GetHeight for EsploraBlockchain {

0 commit comments

Comments
 (0)