]> Untitled Git - bdk/commitdiff
Implement Deref<Target=UrlClient> for EsploraBlockchain
authorVladimir Fomene <vladimirfomene@gmail.com>
Mon, 15 Aug 2022 16:31:35 +0000 (19:31 +0300)
committerVladimir Fomene <vladimirfomene@gmail.com>
Mon, 15 Aug 2022 16:34:57 +0000 (19:34 +0300)
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.

src/blockchain/esplora/reqwest.rs
src/blockchain/esplora/ureq.rs

index 302e811fd3dc6f9ed7af2427e2b36c9b62b1c776..b549f30a3cb66724bb95a5654f99ac2afdbe0cca 100644 (file)
@@ -12,6 +12,7 @@
 //! Esplora by way of `reqwest` HTTP client.
 
 use std::collections::{HashMap, HashSet};
+use std::ops::Deref;
 
 use bitcoin::consensus::{deserialize, serialize};
 use bitcoin::hashes::hex::{FromHex, ToHex};
@@ -31,8 +32,9 @@ use crate::database::BatchDatabase;
 use crate::error::Error;
 use crate::FeeRate;
 
+/// Structure 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.
@@ -101,6 +103,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]
index 9899b90462dc958a2048a623c4b890bb00a94b20..7a9388a0857fe6269eff5167da48cf9d959f948d 100644 (file)
@@ -14,6 +14,7 @@
 use std::collections::{HashMap, HashSet};
 use std::io;
 use std::io::Read;
+use std::ops::Deref;
 use std::time::Duration;
 
 #[allow(unused_imports)]
@@ -33,8 +34,9 @@ use crate::database::BatchDatabase;
 use crate::error::Error;
 use crate::FeeRate;
 
+/// Structure encapsulates ureq Esplora client
 #[derive(Debug, Clone)]
-struct UrlClient {
+pub struct UrlClient {
     url: String,
     agent: Agent,
 }
@@ -98,6 +100,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 {