Skip to content

Commit

Permalink
Implement Deref<Target=UrlClient> for EsploraBlockchain
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vladimirfomene committed Aug 15, 2022
1 parent e8dc9a0 commit 9e32b3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/blockchain/esplora/reqwest.rs
Expand Up @@ -31,8 +31,9 @@ use crate::database::BatchDatabase;
use crate::error::Error;
use crate::FeeRate;

/// Structure that encapsulates Esplora client
#[derive(Debug)]
struct UrlClient {
pub struct UrlClient {
url: String,
// We use the async client instead of the blocking one because it automatically uses `fetch`
// when the target platform is wasm32.
Expand Down Expand Up @@ -101,6 +102,14 @@ impl Blockchain for EsploraBlockchain {
}
}

impl Deref for EsploraBlockchain {
type Target = UrlClient;

fn deref(&self) -> &Self::Target {
&self.url_client
}
}

impl StatelessBlockchain for EsploraBlockchain {}

#[maybe_async]
Expand Down
11 changes: 10 additions & 1 deletion src/blockchain/esplora/ureq.rs
Expand Up @@ -33,8 +33,9 @@ use crate::database::BatchDatabase;
use crate::error::Error;
use crate::FeeRate;

/// Structure that encapsulates Esplora client
#[derive(Debug, Clone)]
struct UrlClient {
pub struct UrlClient {
url: String,
agent: Agent,
}
Expand Down Expand Up @@ -98,6 +99,14 @@ impl Blockchain for EsploraBlockchain {
}
}

impl Deref for EsploraBlockchain {
type Target = UrlClient;

fn deref(&self) -> &Self::Target {
&self.url_client
}
}

impl StatelessBlockchain for EsploraBlockchain {}

impl GetHeight for EsploraBlockchain {
Expand Down

0 comments on commit 9e32b3a

Please sign in to comment.