esplora-api 0.1.0

Simple wrapper to use Blockstream API or self hosted Esplora API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
use std::collections::HashMap;
use reqwest;
use crate::data::blockstream::{
    AddressInfoFormat, BlockFormat, BlockStatus, MemPoolFormat, MempoolTxFormat, MerkleProofFormat,
    OutspentFormat, TransactionFormat, TxStatusFormat, UtxoFormat,
};
/// Client to call esplora api, it use and Esplora Api Url. I can use custom reqwest Client build from reqwest client builder
#[derive(Debug)]
pub struct ApiClient {
    pub url: String,
    pub reqwest: reqwest::blocking::Client,
}
/// Client basics options used to custom reqwest client
#[derive(Debug)]
pub struct ClientOptions {
    pub headers: Option<HeadersOptions>,
}
/// Headers options can be used to use authorization header
#[derive(Debug)]
pub struct HeadersOptions {
    pub authorization: Option<String>,
}
impl ApiClient {
    /// new client from endpoint Esplora Api Url, and ClientOptions.
    /// 
    /// Example without options :
    /// ````rust
    /// use esplora_api::blocking::ApiClient;
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://some_esplora_url.com", None);
    /// }
    /// ````
    /// Example with custom authorization header :
    /// ````rust
    /// use esplora_api::blocking::{ApiClient, ClientOptions, HeadersOptions};
    /// fn main(){
    ///     let options = ClientOptions { headers: Some( HeadersOptions { authorization: Some("secret".to_string())}),};
    ///     let client = esplora_api::blocking::ApiClient::new("https://some_esplora_url.com", Some(options));
    /// }
    /// ````
    pub fn new(
        url: &str,
        options: Option<ClientOptions>,
    ) -> Result<Self, Box<dyn std::error::Error>> {
        let mut client_builder = reqwest::blocking::ClientBuilder::new();
        // Find options
        match options {
            // Build headers
            Some(ClientOptions { headers, .. }) => {
                let mut headers_map = reqwest::header::HeaderMap::new();
                match headers {
                    // header::AUTHORIZATION
                    Some(HeadersOptions {
                        authorization: Some(authorization),
                    }) => {
                        headers_map.insert(
                            reqwest::header::AUTHORIZATION,
                            reqwest::header::HeaderValue::from_str(&authorization).unwrap(),
                        );
                    }
                    _ => (),
                }
                client_builder = client_builder.default_headers(headers_map);
            }
            None => (),
        }
        let build = client_builder
            .build()
            .unwrap_or(reqwest::blocking::Client::new());

        Ok(ApiClient {
            url: url.to_string(),
            reqwest: build,
        })
    }
    /// new_from_config new client from endpoint Esplora Api Url, and reqwest client.
    /// 
    /// Example without custom reqwest client :
    /// ````rust
    /// use esplora_api::blocking::ApiClient;
    /// use reqwest;
    /// use reqwest::header;
    /// fn main(){
    ///     let mut headers = header::HeaderMap::new();
    ///     headers.insert(header::AUTHORIZATION,header::HeaderValue::from_static("secret"));
    ///     let reqwest_client = reqwest::blocking::Client::builder().default_headers(headers).build().unwrap();
    ///     let client = esplora_api::blocking::ApiClient::new_from_config("https://some_esplora_url.com", reqwest_client);
    /// }
    /// ````
    pub fn new_from_config(
        url: &str,
        client: reqwest::blocking::Client
    )->Result<Self, Box<dyn std::error::Error>> {
        Ok(ApiClient {
            url: url.to_string(),
            reqwest: client,
        })
    }
    /// get_block Returns information about a block.
    ///
    /// Route : GET /block/:hash. Available fields:
    ///
    /// Elements-based chains have an additional proof field. See block format for more details.
    /// The response from this endpoint can be cached indefinitely.
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_block("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_block(&self, hash: &str) -> Result<BlockFormat, Box<dyn std::error::Error>> {
        let request_url = format!("{}/block/{}", self.url, hash);
        let resp: BlockFormat = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_block_status Returns the block status.
    ///
    /// Route : GET /block/:hash/status. Available fields:
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_block_status("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_block_status(&self, hash: &str) -> Result<BlockStatus, Box<dyn std::error::Error>> {
        let request_url = format!("{}/block/{}/status", self.url, hash);
        let resp: BlockStatus = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_block_txs Returns a list of transactions in the block (up to 25 transactions beginning at start_index).
    ///
    /// Route : GET /block/:hash/txs[/:start_index]
    ///
    /// Transactions returned here do not have the status field, since all the transactions share the same block and confirmation status.
    /// The response from this endpoint can be cached indefinitely.
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_block_txs("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7", Some(25)).unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_block_txs(
        &self,
        hash: &str,
        start_index: Option<i32>,
    ) -> Result<Vec<TransactionFormat>, Box<dyn std::error::Error>> {
        let request_url = if let Some(i) = start_index {
            format!("{}/block/{}/txs/{}", self.url, hash, i)
        } else {
            format!("{}/block/{}/txs", self.url, hash)
        };
        let resp: Vec<TransactionFormat> = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_block_txids Returns a list of all txids in the block.
    ///
    /// Route : GET /block/:hash/txids
    ///
    ///The response from this endpoint can be cached indefinitely.
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_block_txids("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_block_txids(&self, hash: &str) -> Result<Vec<String>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/block/{}/txids", self.url, hash);
        let resp: Vec<String> = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_block_txid_at_index Returns the transaction at index :index within the specified block.
    ///
    /// Route : GET /block/:hash/txid/:index
    ///
    /// The response from this endpoint can be cached indefinitely.
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_block_txid_at_index("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7",25).unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_block_txid_at_index(
        &self,
        hash: &str,
        index: i32,
    ) -> Result<String, Box<dyn std::error::Error>> {
        let request_url = format!(
            "{}/block/{}/txid/{}",
            self.url,
            hash,
            index.to_string()
        );
        let resp: String = self.reqwest.get(&request_url).send()?.text()?;
        Ok(resp.clone())
    }
    /// get_block_raw_format Returns the raw block representation in binary.
    ///
    /// Route : GET /block/:hash/raw
    ///
    /// The response from this endpoint can be cached indefinitely.
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_block_raw_format("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_block_raw_format(&self, hash: &str) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/block/{}/raw", self.url, hash);
        let resp = self.reqwest.get(&request_url).send()?.bytes()?.to_vec();
        Ok(resp)
    }

    /// get_block_height Returns the hash of the block currently at height.
    ///
    /// Route : GET /block-height/:height
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_block_height(424242).unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_block_height(&self, height: i32) -> Result<String, Box<dyn std::error::Error>> {
        let request_url = format!("{}/block-height/{}", self.url, height);
        let resp = self.reqwest.get(&request_url).send()?.text()?;
        Ok(resp)
    }
    /// get_blocks Returns the 10 newest blocks starting at the tip or at start_height if specified.
    ///
    /// Route : GET /blocks[/:start_height]
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_blocks(1234).unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_blocks(
        &self,
        start_height: i32,
    ) -> Result<Vec<BlockFormat>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/blocks/{}", self.url, start_height);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_blocks_tip_height Returns the height of the last block.
    ///
    /// Route : GET /blocks/tip/height
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_blocks_tip_height().unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_blocks_tip_height(&self) -> Result<i32, Box<dyn std::error::Error>> {
        let request_url = format!("{}/blocks/tip/height", self.url);
        let resp = self.reqwest.get(&request_url).send()?.text()?.parse()?;
        Ok(resp)
    }
    /// get_blocks_tip_hash Returns the hash of the last block.
    ///
    /// Route : GET /blocks/tip/hash
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_blocks_tip_height().unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````

    pub fn get_blocks_tip_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
        let request_url = format!("{}/blocks/tip/hash", self.url);
        let resp = self.reqwest.get(&request_url).send()?.text()?;
        Ok(resp)
    }
    /// get_tx Returns information about the transaction. Available fields: txid, version, locktime, size, weight, fee, vin, vout and status (see transaction format for details).
    ///
    /// Route : GET /tx/:txid
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_tx("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_tx(&self, txid: &str) -> Result<TransactionFormat, Box<dyn std::error::Error>> {
        let request_url = format!("{}/tx/{}", self.url, txid);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_tx_status Returns the transaction confirmation status. Available fields: confirmed (boolean), block_height (optional) and block_hash (optional).
    ///
    /// Route : GET /tx/:txid/status
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_tx_status("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_tx_status(&self, txid: &str) -> Result<TxStatusFormat, Box<dyn std::error::Error>> {
        let request_url = format!("{}/tx/{}/status", self.url, txid);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_tx_raw Returns the raw transaction as binary data.
    ///
    /// Route : GET /tx/:txid/raw
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_tx_raw("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_tx_raw(&self, txid: &str) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/tx/{}/raw", self.url, txid);
        let resp = self.reqwest.get(&request_url).send()?.bytes()?.to_vec();
        Ok(resp)
    }
    /// get_tx_hex Returns the raw transaction in hex
    ///
    /// Route : GET /tx/:txid/hex
    ///
    /// Example :
    /// ````rust
    /// 
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_tx_hex("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_tx_hex(&self, txid: &str) -> Result<String, Box<dyn std::error::Error>> {
        let request_url = format!("{}/tx/{}/raw", self.url, txid);
        let resp = self.reqwest.get(&request_url).send()?.text()?;
        Ok(resp)
    }
    /// get_tx_merkleblock_proof Returns a merkle inclusion proof for the transaction using bitcoind's merkleblock format.
    /// Note: This endpoint is not currently available for Liquid/Elements-based chains.
    /// Route : GET /tx/:txid/merkleblock-proof
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_tx_merkleblock_proof("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_tx_merkleblock_proof(
        &self,
        txid: &str,
    ) -> Result<String, Box<dyn std::error::Error>> {
        let request_url = format!("{}/tx/{}/merkleblock-proof", self.url, txid);
        let resp = self.reqwest.get(&request_url).send()?.text()?;
        Ok(resp)
    }
    /// get_tx_merkle_proof Returns a merkle inclusion proof for the transaction using Electrum's blockchain.transaction.get_merkle format.
    ///
    /// Route : GET /tx/:txid/merkle-proof
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_tx_merkle_proof("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_tx_merkle_proof(
        &self,
        txid: &str,
    ) -> Result<MerkleProofFormat, Box<dyn std::error::Error>> {
        let request_url = format!("{}/tx/{}/merkle-proof", self.url, txid);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_tx_outspend Returns the spending status of a transaction output.
    /// Available fields: spent (boolean), txid (optional), vin (optional) and status (optional, the status of the spending tx).
    ///
    /// Route : GET /tx/:txid/outspend/:vout
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_tx_outspend("fac9af7f793330af3cc0bce4790d98499c59d47a125af7260edd61d647003316",Some(1)).unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_tx_outspend(
        &self,
        txid: &str,
        vout: Option<i32>,
    ) -> Result<OutspentFormat, Box<dyn std::error::Error>> {
        let request_url = if let Some(vout_idx) = vout {
            format!("{}/tx/{}/outspend/{}", self.url, txid, vout_idx)
        } else {
            format!("{}/tx/{}/outspend", self.url, txid) // FIXME: not sure if this exist
        };
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_tx_outspends Returns the spending status of all transaction outputs.
    ///
    /// Route : GET /tx/:txid/outspends
    ///
    /// Example :
    /// ````rust
    /// 
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_tx_outspends("fac9af7f793330af3cc0bce4790d98499c59d47a125af7260edd61d647003316").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_tx_outspends(
        &self,
        txid: &str,
    ) -> Result<Vec<OutspentFormat>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/tx/{}/outspends", self.url, txid);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// post_tx Broadcast a raw transaction to the network.
    /// The transaction should be provided as hex in the request body. The txid will be returned on success.
    ///
    /// Route : POST /tx
    ///
    pub fn post_tx(&self, hex_transaction: &str) -> Result<String, Box<dyn std::error::Error>> {
        let request_url = format!("{}/tx", self.url);
        let resp = self
            .reqwest
            .post(&request_url)
            .body(hex_transaction.to_string())
            .send()?
            .text()?;
        Ok(resp)
    }
    /// get_address Get information about an address
    /// Available fields: address/scripthash, chain_stats and mempool_stats.
    /// {chain,mempool}_stats each contain an object with tx_count, funded_txo_count, funded_txo_sum, spent_txo_count and spent_txo_sum.
    /// Elements-based chains don't have the {funded,spent}_txo_sum fields.
    ///
    /// Route : GET /address/:address
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_address("2MvJVm11phGoxEekPB8Hw2Tksb57eVRGHC5").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_address(
        &self,
        address: &str,
    ) -> Result<AddressInfoFormat, Box<dyn std::error::Error>> {
        let request_url = format!("{}/address/{}", self.url, address);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_script_hash Get information about an scripthash
    /// Available fields: scripthash, chain_stats and mempool_stats.
    /// {chain,mempool}_stats each contain an object with tx_count, funded_txo_count, funded_txo_sum, spent_txo_count and spent_txo_sum.
    /// Elements-based chains don't have the {funded,spent}_txo_sum fields.
    ///
    /// Route : GET /scripthash/:hash
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_script_hash("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_script_hash(
        &self,
        scripthash: &str,
    ) -> Result<AddressInfoFormat, Box<dyn std::error::Error>> {
        let request_url = format!("{}/scripthash/{}", self.url, scripthash);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_address_txs Get transaction history for the specified address/scripthash, sorted with newest first.
    /// Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using :last_seen_txid(see below).
    ///
    /// Route : GET /address/:address/txs
    ///
    /// Example :
    /// ````rust
    /// 
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_address_txs("2MvJVm11phGoxEekPB8Hw2Tksb57eVRGHC5").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_address_txs(
        &self,
        address: &str,
    ) -> Result<Vec<TransactionFormat>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/address/{}/txs", self.url,  address);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_script_hash_txs Get transaction history for the specified address/scripthash, sorted with newest first.
    /// Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using :last_seen_txid(see below).
    ///
    /// Route : GET /scripthash/:hash/txs
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_script_hash_txs("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_script_hash_txs(
        &self,
        scripthash: &str,
    ) -> Result<Vec<TransactionFormat>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/scripthash/{}/txs", self.url, scripthash);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_address_txs_chain Get confirmed transaction history for the specified address/scripthash, sorted with newest first.
    /// Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query.
    ///
    /// Route : GET /address/:address/txs/chain[/:last_seen_txid]
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_address_txs_chain("n1vgV8XmoggmRXzW3hGD8ZNTAgvhcwT4Gk",Some("d0075b62f8b3e464472b8edecf56083ca3e9e8424f5f332ed2f9045d7fcccddc")).unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_address_txs_chain(
        &self,
        address: &str,
        txid: Option<&str>,
    ) -> Result<Vec<TransactionFormat>, Box<dyn std::error::Error>> {
        let request_url = if let Some(id) = txid {
            format!("{}/address/{}/txs/chain/{}", self.url, address, id)
        } else {
            format!("{}/address/{}/txs/chain", self.url, address)
        };
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_script_hash_txs_chain Get confirmed transaction history for the specified address/scripthash, sorted with newest first.
    /// Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query.
    ///
    /// Route : GET /scripthash/:hash/txs/chain[/:last_seen_txid]
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_script_hash_txs_chain("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c",None).unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_script_hash_txs_chain(
        &self,
        scripthash: &str,
        txid: Option<&str>,
    ) -> Result<Vec<TransactionFormat>, Box<dyn std::error::Error>> {
        let request_url = if let Some(id) = txid {
            format!("{}/scripthash/{}/txs/chain/{}", self.url, scripthash, id)
        } else {
            format!("{}/scripthash/{}/txs/chain", self.url, scripthash)
        };
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_address_txs_mempool Get unconfirmed transaction history for the specified address.
    /// Returns up to 50 transactions (no paging).
    ///
    /// Route : GET /address/:address/txs/mempool
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_address_txs_mempool("2MvJVm11phGoxEekPB8Hw2Tksb57eVRGHC5").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_address_txs_mempool(
        &self,
        address: &str,
    ) -> Result<Vec<TransactionFormat>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/address/{}/txs/mempool", self.url, address);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_script_hash_txs_mempool Get unconfirmed transaction history for the specified scripthash.
    /// Returns up to 50 transactions (no paging).
    ///
    /// Route : GET /scripthash/:hash/txs/mempool
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_script_hash_txs_mempool("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_script_hash_txs_mempool(
        &self,
        scripthash: &str,
    ) -> Result<Vec<TransactionFormat>, Box<dyn std::error::Error>> {
        let request_url = format!(
            "{}/scripthash/{}/txs/mempool",
            self.url, scripthash
        );
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_address_utxo Get the list of unspent transaction outputs associated with the address
    /// Available fields: txid, vout, value and status (with the status of the funding tx).
    /// Elements-based chains have a valuecommitment field that may appear in place of value, plus the following additional fields: asset/assetcommitment, nonce/noncecommitment, surjection_proof and range_proof.
    ///
    /// Route : GET /address/:address/utxo
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_address_utxo("2NDcM3CGUTwqFL7y8BSBJTYJ9kToeXawkUF").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_address_utxo(
        &self,
        address: &str,
    ) -> Result<Vec<UtxoFormat>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/address/{}/utxo", self.url, address);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_script_hash_utxo Get the list of unspent transaction outputs associated with the address
    /// Available fields: txid, vout, value and status (with the status of the funding tx).
    /// Elements-based chains have a valuecommitment field that may appear in place of value, plus the following additional fields: asset/assetcommitment, nonce/noncecommitment, surjection_proof and range_proof.
    ///
    /// Route : GET /scripthash/:hash/utxo
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_script_hash_utxo("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_script_hash_utxo(
        &self,
        scripthash: &str,
    ) -> Result<Vec<UtxoFormat>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/scripthash/{}/utxo", self.url, scripthash);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_address_prefix  This feature is disabled by default on custom api Search for addresses beginning with :prefix.
    /// Returns a JSON array with up to 10 results.
    ///
    /// Route : GET /address-prefix/:prefix
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_address_prefix("2NDcM").unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_address_prefix(
        &self,
        prefix: &str,
    ) -> Result<Vec<String>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/address-prefix/{}", self.url, prefix);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_mempool Get mempool backlog statistics. Returns an object with:
    ///     count: the number of transactions in the mempool
    ///     vsize: the total size of mempool transactions in virtual bytes
    ///     total_fee: the total fee paid by mempool transactions in satoshis
    ///     fee_histogram: mempool fee-rate distribution histogram
    ///     An array of (feerate, vsize) tuples, where each entry's vsize is the total vsize of transactions paying more than feerate but less than the previous entry's feerate (except for the first entry, which has no upper bound). This matches the format used by the Electrum RPC protocol for mempool.get_fee_histogram.
    ///
    /// Route : GET /mempool
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_mempool().unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    /// Example output:
    /// ````json
    /// {
    ///   "count": 8134,
    ///   "vsize": 3444604,
    ///   "total_fee":29204625,
    ///   "fee_histogram": [[53.01, 102131], [38.56, 110990], [34.12, 138976], [24.34, 112619], [3.16, 246346], [2.92, 239701], [1.1, 775272]]
    /// }
    /// ````
    /// In this example, there are transactions weighting a total of 102,131 vbytes that are paying more than 53 sat/vB, 110,990 vbytes of transactions paying between 38 and 53 sat/vB, 138,976 vbytes paying between 34 and 38, etc.
    pub fn get_mempool(&self) -> Result<MemPoolFormat, Box<dyn std::error::Error>> {
        let request_url = format!("{}/mempool", self.url);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_mempool_txids Get the full list of txids in the mempool as an array.
    /// The order of the txids is arbitrary and does not match bitcoind's.
    ///
    /// Route : GET /mempool/txids
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_mempool_txids().unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_mempool_txids(&self) -> Result<Vec<String>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/mempool/txids", self.url);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// get_mempool_recent  Get a list of the last 10 transactions to enter the mempool. Each transaction object contains simplified overview data, with the following fields: txid, fee, vsize and value
    /// Fee estimates
    /// The order of the txids is arbitrary and does not match bitcoind's.
    ///
    /// Route : GET /mempool/recent
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.get_mempool_recent().unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn get_mempool_recent(&self) -> Result<Vec<MempoolTxFormat>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/mempool/recent", self.url);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
    /// fee_estimate Get an object where the key is the confirmation target (in number of blocks) and the value is the estimated feerate (in sat/vB).
    /// The available confirmation targets are 1-25, 144, 504 and 1008 blocks.
    /// For example: { "1": 87.882, "2": 87.882, "3": 87.882, "4": 87.882, "5": 81.129, "6": 68.285, ..., "144": 1.027, "504": 1.027, "1008": 1.027 }
    ///
    /// Route : GET /fee-estimates
    ///
    /// Example :
    /// ````rust
    /// 
    /// fn main(){
    ///     let client = esplora_api::blocking::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
    ///     let response = client.fee_estimate().unwrap();
    ///     println!("{:?}",response);
    ///     
    /// }
    /// ````
    pub fn fee_estimate(&self) -> Result<HashMap<String, f32>, Box<dyn std::error::Error>> {
        let request_url = format!("{}/fee-estimates", self.url);
        let resp = self.reqwest.get(&request_url).send()?.json()?;
        Ok(resp)
    }
}