Merge bitcoindevkit/bdk#722: Implement Deref<Target=UrlClient> for EsploraBlockchain
baf7eaace66edcae8bf3252a962b9417b704ba26 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 baf7eaace66edcae8bf3252a962b9417b704ba26 Tree-SHA512: e2f530058c88e06fc2972edfcd2df1b534d43b0214d710b62e4d5200ac0e38dad6a9f8db1e0c7a7ed19892e59411dcc07f3f6dc8ad58afae9d677169ca98bb38
This commit is contained in:
commit
a5d1a3d65c
@ -12,6 +12,7 @@
|
|||||||
//! Esplora by way of `reqwest` HTTP client.
|
//! Esplora by way of `reqwest` HTTP client.
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
use bitcoin::consensus::{deserialize, serialize};
|
use bitcoin::consensus::{deserialize, serialize};
|
||||||
use bitcoin::hashes::hex::{FromHex, ToHex};
|
use bitcoin::hashes::hex::{FromHex, ToHex};
|
||||||
@ -31,8 +32,9 @@ use crate::database::BatchDatabase;
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::FeeRate;
|
use crate::FeeRate;
|
||||||
|
|
||||||
|
/// Structure encapsulates Esplora client
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct UrlClient {
|
pub struct UrlClient {
|
||||||
url: String,
|
url: String,
|
||||||
// We use the async client instead of the blocking one because it automatically uses `fetch`
|
// We use the async client instead of the blocking one because it automatically uses `fetch`
|
||||||
// when the target platform is wasm32.
|
// 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 {}
|
impl StatelessBlockchain for EsploraBlockchain {}
|
||||||
|
|
||||||
#[maybe_async]
|
#[maybe_async]
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
use std::ops::Deref;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
@ -33,8 +34,9 @@ use crate::database::BatchDatabase;
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::FeeRate;
|
use crate::FeeRate;
|
||||||
|
|
||||||
|
/// Structure encapsulates ureq Esplora client
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct UrlClient {
|
pub struct UrlClient {
|
||||||
url: String,
|
url: String,
|
||||||
agent: Agent,
|
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 StatelessBlockchain for EsploraBlockchain {}
|
||||||
|
|
||||||
impl GetHeight for EsploraBlockchain {
|
impl GetHeight for EsploraBlockchain {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user