1
- //! Esplora
1
+ //! An extensible blocking/async Esplora client
2
2
//!
3
- //! This module defines a [`Builder`] struct that can create a blocking or
4
- //! async Esplora client to query an Esplora backend:
3
+ //! This library provides an extensible blocking and
4
+ //! async Esplora client to query Esplora's backend.
5
5
//!
6
- //! ## Examples
6
+ //! The library provides the possibility to build a blocking
7
+ //! client using [`ureq`] and an async client using [`reqwest`].
8
+ //! The library supports communicating to Esplora via a proxy
9
+ //! and also using TLS (SSL) for secure communication.
10
+ //!
11
+ //!
12
+ //! ## Usage
13
+ //!
14
+ //! You can create a blocking client as follows:
7
15
//!
8
16
//! ```no_run
9
- //! # use esplora_client::Builder;
17
+ //! use esplora_client::Builder;
10
18
//! let builder = Builder::new("https://blockstream.info/testnet/api");
11
19
//! let blocking_client = builder.build_blocking();
12
20
//! # Ok::<(), esplora_client::Error>(());
13
21
//! ```
22
+ //!
23
+ //! Here is an example of how to create an asynchronous client.
24
+ //!
14
25
//! ```no_run
15
- //! # use esplora_client::Builder;
26
+ //! use esplora_client::Builder;
16
27
//! let builder = Builder::new("https://blockstream.info/testnet/api");
17
28
//! let async_client = builder.build_async();
18
29
//! # Ok::<(), esplora_client::Error>(());
19
30
//! ```
20
31
//!
21
- //! Esplora client can use either `ureq` or `reqwest` for the HTTP client
22
- //! depending on your needs (blocking or async respectively).
32
+ //! ## Features
33
+ //!
34
+ //! By default the library enables all features. To specify
35
+ //! specific features, set `default-features` to `false` in your `Cargo.toml`
36
+ //! and specify the features you want. This will look like this:
37
+ //!
38
+ //! `esplora_client = { version = "*", default-features = false, features = ["blocking"] }`
39
+ //!
40
+ //! * `blocking` enables [`ureq`], the blocking client with proxy and TLS (SSL) capabilities.
41
+ //! * `async` enables [`reqwest`], the async client with proxy capabilities.
42
+ //! * `async-https` enables [`reqwest`], the async client with support for proxying and TLS (SSL).
43
+ //!
23
44
//!
24
- //! Please note, to configure the Esplora HTTP client correctly use one of:
25
- //! Blocking: --features='blocking'
26
- //! Async: --features='async'
27
45
use std:: collections:: HashMap ;
28
46
use std:: fmt;
29
47
use std:: io;
@@ -44,6 +62,8 @@ pub use blocking::BlockingClient;
44
62
#[ cfg( any( feature = "async" , feature = "async-https" ) ) ]
45
63
pub use r#async:: AsyncClient ;
46
64
65
+ /// Get a fee value in sats/vbytes from the estimates
66
+ /// that matches the confirmation target set as parameter.
47
67
pub fn convert_fee_rate ( target : usize , estimates : HashMap < String , f64 > ) -> Result < f32 , Error > {
48
68
let fee_val = {
49
69
let mut pairs = estimates
@@ -79,6 +99,7 @@ pub struct Builder {
79
99
}
80
100
81
101
impl Builder {
102
+ /// Instantiate a new builder
82
103
pub fn new ( base_url : & str ) -> Self {
83
104
Builder {
84
105
base_url : base_url. to_string ( ) ,
@@ -87,28 +108,32 @@ impl Builder {
87
108
}
88
109
}
89
110
111
+ /// Set the proxy of the builder
90
112
pub fn proxy ( mut self , proxy : & str ) -> Self {
91
113
self . proxy = Some ( proxy. to_string ( ) ) ;
92
114
self
93
115
}
94
116
117
+ /// Set the timeout of the builder
95
118
pub fn timeout ( mut self , timeout : u64 ) -> Self {
96
119
self . timeout = Some ( timeout) ;
97
120
self
98
121
}
99
122
123
+ /// build a blocking client from builder
100
124
#[ cfg( feature = "blocking" ) ]
101
125
pub fn build_blocking ( self ) -> Result < BlockingClient , Error > {
102
126
BlockingClient :: from_builder ( self )
103
127
}
104
128
129
+ // build an asynchronous client from builder
105
130
#[ cfg( feature = "async" ) ]
106
131
pub fn build_async ( self ) -> Result < AsyncClient , Error > {
107
132
AsyncClient :: from_builder ( self )
108
133
}
109
134
}
110
135
111
- /// Errors that can happen during a sync with [`EsploraBlockchain`]
136
+ /// Errors that can happen during a sync with `Esplora`
112
137
#[ derive( Debug ) ]
113
138
pub enum Error {
114
139
/// Error during ureq HTTP request
0 commit comments