14
14
use std:: collections:: HashMap ;
15
15
use std:: str:: FromStr ;
16
16
17
- use arti_client:: { TorClient , TorClientConfig } ;
18
-
19
- use arti_hyper:: ArtiHttpConnector ;
20
-
21
17
use bitcoin:: consensus:: { deserialize, serialize} ;
22
18
use bitcoin:: hashes:: hex:: FromHex ;
23
19
use bitcoin:: hashes:: { sha256, Hash } ;
@@ -26,26 +22,38 @@ use bitcoin::{
26
22
} ;
27
23
use bitcoin_internals:: hex:: display:: DisplayHex ;
28
24
29
- use hyper:: { Body , Response , Uri } ;
30
25
#[ allow( unused_imports) ]
31
26
use log:: { debug, error, info, trace} ;
32
27
33
- use reqwest:: { Client , StatusCode } ;
34
- use tls_api:: { TlsConnector as TlsConnectorTrait , TlsConnectorBuilder } ;
28
+ #[ cfg( feature = "async" ) ]
29
+ use reqwest:: Client ;
30
+
31
+ #[ cfg( feature = "async-arti-hyper" ) ]
32
+ use {
33
+ arti_client:: { TorClient , TorClientConfig } ,
34
+ arti_hyper:: ArtiHttpConnector ,
35
+ hyper:: { Body , Response , Uri } ,
36
+ tls_api:: { TlsConnector as TlsConnectorTrait , TlsConnectorBuilder } ,
37
+ tor_rtcompat:: PreferredRuntime ,
38
+ } ;
39
+
40
+ #[ cfg( feature = "async-arti-hyper" ) ]
35
41
#[ cfg( not( target_vendor = "apple" ) ) ]
36
42
use tls_api_native_tls:: TlsConnector ;
43
+ #[ cfg( feature = "async-arti-hyper" ) ]
37
44
#[ cfg( target_vendor = "apple" ) ]
38
45
use tls_api_openssl:: TlsConnector ;
39
- use tor_rtcompat:: PreferredRuntime ;
40
46
41
47
use crate :: { BlockStatus , BlockSummary , Builder , Error , MerkleProof , OutputStatus , Tx , TxStatus } ;
42
48
49
+ #[ cfg( feature = "async" ) ]
43
50
#[ derive( Debug , Clone ) ]
44
51
pub struct AsyncClient {
45
52
url : String ,
46
53
client : Client ,
47
54
}
48
55
56
+ #[ cfg( feature = "async" ) ]
49
57
impl AsyncClient {
50
58
/// build an async client from a builder
51
59
pub fn from_builder ( builder : Builder ) -> Result < Self , Error > {
@@ -77,7 +85,7 @@ impl AsyncClient {
77
85
. send ( )
78
86
. await ?;
79
87
80
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
88
+ if let reqwest :: StatusCode :: NOT_FOUND = resp. status ( ) {
81
89
return Ok ( None ) ;
82
90
}
83
91
@@ -112,7 +120,7 @@ impl AsyncClient {
112
120
. send ( )
113
121
. await ?;
114
122
115
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
123
+ if let reqwest :: StatusCode :: NOT_FOUND = resp. status ( ) {
116
124
return Ok ( None ) ;
117
125
}
118
126
@@ -198,7 +206,7 @@ impl AsyncClient {
198
206
. send ( )
199
207
. await ?;
200
208
201
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
209
+ if let reqwest :: StatusCode :: NOT_FOUND = resp. status ( ) {
202
210
return Ok ( None ) ;
203
211
}
204
212
@@ -220,7 +228,7 @@ impl AsyncClient {
220
228
. send ( )
221
229
. await ?;
222
230
223
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
231
+ if let reqwest :: StatusCode :: NOT_FOUND = resp. status ( ) {
224
232
return Ok ( None ) ;
225
233
}
226
234
@@ -242,7 +250,7 @@ impl AsyncClient {
242
250
. send ( )
243
251
. await ?;
244
252
245
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
253
+ if let reqwest :: StatusCode :: NOT_FOUND = resp. status ( ) {
246
254
return Ok ( None ) ;
247
255
}
248
256
@@ -269,7 +277,7 @@ impl AsyncClient {
269
277
. send ( )
270
278
. await ?;
271
279
272
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
280
+ if let reqwest :: StatusCode :: NOT_FOUND = resp. status ( ) {
273
281
return Ok ( None ) ;
274
282
}
275
283
@@ -346,7 +354,7 @@ impl AsyncClient {
346
354
. send ( )
347
355
. await ?;
348
356
349
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
357
+ if let reqwest :: StatusCode :: NOT_FOUND = resp. status ( ) {
350
358
return Err ( Error :: HeaderHeightNotFound ( block_height) ) ;
351
359
}
352
360
@@ -441,12 +449,14 @@ impl AsyncClient {
441
449
}
442
450
}
443
451
452
+ #[ cfg( feature = "async-arti-hyper" ) ]
444
453
#[ derive( Debug , Clone ) ]
445
454
pub struct AsyncAnonymizedClient {
446
455
url : String ,
447
456
client : hyper:: Client < ArtiHttpConnector < PreferredRuntime , TlsConnector > > ,
448
457
}
449
458
459
+ #[ cfg( feature = "async-arti-hyper" ) ]
450
460
impl AsyncAnonymizedClient {
451
461
/// build an async [`TorClient`] with default Tor configuration
452
462
async fn create_tor_client ( ) -> Result < TorClient < PreferredRuntime > , arti_client:: Error > {
@@ -485,7 +495,7 @@ impl AsyncAnonymizedClient {
485
495
486
496
let resp = self . client . get ( uri) . await ?;
487
497
488
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
498
+ if let hyper :: StatusCode :: NOT_FOUND = resp. status ( ) {
489
499
return Ok ( None ) ;
490
500
}
491
501
@@ -521,7 +531,7 @@ impl AsyncAnonymizedClient {
521
531
522
532
let resp = self . client . get ( uri) . await ?;
523
533
524
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
534
+ if let hyper :: StatusCode :: NOT_FOUND = resp. status ( ) {
525
535
return Ok ( None ) ;
526
536
}
527
537
@@ -604,7 +614,7 @@ impl AsyncAnonymizedClient {
604
614
let uri = Uri :: from_str ( & path) . map_err ( |_| Error :: InvalidUri ) ?;
605
615
let resp = self . client . get ( uri) . await ?;
606
616
607
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
617
+ if let hyper :: StatusCode :: NOT_FOUND = resp. status ( ) {
608
618
return Ok ( None ) ;
609
619
}
610
620
@@ -627,7 +637,7 @@ impl AsyncAnonymizedClient {
627
637
628
638
let resp = self . client . get ( uri) . await ?;
629
639
630
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
640
+ if let hyper :: StatusCode :: NOT_FOUND = resp. status ( ) {
631
641
return Ok ( None ) ;
632
642
}
633
643
@@ -652,7 +662,7 @@ impl AsyncAnonymizedClient {
652
662
653
663
let resp = self . client . get ( uri) . await ?;
654
664
655
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
665
+ if let hyper :: StatusCode :: NOT_FOUND = resp. status ( ) {
656
666
return Ok ( None ) ;
657
667
}
658
668
@@ -678,7 +688,7 @@ impl AsyncAnonymizedClient {
678
688
let uri = Uri :: from_str ( path) . map_err ( |_| Error :: InvalidUri ) ?;
679
689
let resp = self . client . get ( uri) . await ?;
680
690
681
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
691
+ if let hyper :: StatusCode :: NOT_FOUND = resp. status ( ) {
682
692
return Ok ( None ) ;
683
693
}
684
694
@@ -697,6 +707,7 @@ impl AsyncAnonymizedClient {
697
707
}
698
708
}
699
709
710
+ // TODO: (@leonardo)
700
711
// /// Broadcast a [`Transaction`] to Esplora
701
712
// pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), Error> {
702
713
// let resp = self
@@ -761,7 +772,7 @@ impl AsyncAnonymizedClient {
761
772
let uri = Uri :: from_str ( path) . map_err ( |_| Error :: InvalidUri ) ?;
762
773
let resp = self . client . get ( uri) . await ?;
763
774
764
- if let StatusCode :: NOT_FOUND = resp. status ( ) {
775
+ if let hyper :: StatusCode :: NOT_FOUND = resp. status ( ) {
765
776
return Err ( Error :: HeaderHeightNotFound ( block_height) ) ;
766
777
}
767
778
0 commit comments