@@ -19,7 +19,7 @@ use std::time::Duration;
19
19
#[ allow( unused_imports) ]
20
20
use log:: { debug, error, info, trace} ;
21
21
22
- use ureq:: { Agent , Response } ;
22
+ use ureq:: { Agent , Proxy , Response } ;
23
23
24
24
use bitcoin:: consensus:: { deserialize, serialize} ;
25
25
use bitcoin:: hashes:: hex:: { FromHex , ToHex } ;
@@ -59,7 +59,7 @@ impl std::convert::From<UrlClient> for EsploraBlockchain {
59
59
}
60
60
61
61
impl EsploraBlockchain {
62
- /// Create a new instance of the client from a base URL and `stop_gap`.
62
+ /// Create a new instance of the client from a base URL and the `stop_gap`.
63
63
pub fn new ( base_url : & str , stop_gap : usize ) -> Self {
64
64
EsploraBlockchain {
65
65
url_client : UrlClient {
@@ -358,6 +358,15 @@ impl ElectrumLikeSync for UrlClient {
358
358
pub struct EsploraBlockchainConfig {
359
359
/// Base URL of the esplora service eg. `https://blockstream.info/api/`
360
360
pub base_url : String ,
361
+ /// Optional URL of the proxy to use to make requests to the Esplora server
362
+ ///
363
+ /// The string should be formatted as: `<protocol>://<user>:<password>@host:<port>`.
364
+ ///
365
+ /// Note that the format of this value and the supported protocols change slightly between the
366
+ /// sync version of esplora (using `ureq`) and the async version (using `reqwest`). For more
367
+ /// details check with the documentation of the two crates. Both of them are compiled with
368
+ /// the `socks` feature enabled.
369
+ pub proxy : Option < String > ,
361
370
/// Socket read timeout.
362
371
pub timeout_read : u64 ,
363
372
/// Socket write timeout.
@@ -370,10 +379,18 @@ impl ConfigurableBlockchain for EsploraBlockchain {
370
379
type Config = EsploraBlockchainConfig ;
371
380
372
381
fn from_config ( config : & Self :: Config ) -> Result < Self , Error > {
373
- let agent : Agent = ureq:: AgentBuilder :: new ( )
382
+ let mut agent_builder = ureq:: AgentBuilder :: new ( )
374
383
. timeout_read ( Duration :: from_secs ( config. timeout_read ) )
375
- . timeout_write ( Duration :: from_secs ( config. timeout_write ) )
376
- . build ( ) ;
377
- Ok ( EsploraBlockchain :: new ( config. base_url . as_str ( ) , config. stop_gap ) . with_agent ( agent) )
384
+ . timeout_write ( Duration :: from_secs ( config. timeout_write ) ) ;
385
+
386
+ if let Some ( proxy) = & config. proxy {
387
+ agent_builder = agent_builder
388
+ . proxy ( Proxy :: new ( proxy) . map_err ( |e| Error :: Esplora ( Box :: new ( e. into ( ) ) ) ) ?) ;
389
+ }
390
+
391
+ Ok (
392
+ EsploraBlockchain :: new ( config. base_url . as_str ( ) , config. stop_gap )
393
+ . with_agent ( agent_builder. build ( ) ) ,
394
+ )
378
395
}
379
396
}
0 commit comments