@@ -6,11 +6,11 @@ use std::process;
6
6
7
7
use crate :: blocking;
8
8
9
- /// mempool-space_ARG
10
- /// mempool-space --arg
11
- /// mempool-space_ARG_STRING
12
- /// mempool-space --arg_string
13
- pub fn generic_sys_call ( option : & str , sub_string : & str ) -> String {
9
+ /// mempool-space --option_str sub_string
10
+ ///
11
+ /// mempool-space_option_str sub_string
12
+ ///
13
+ pub fn api ( option : & str , sub_string : & str ) -> String {
14
14
use std:: process:: Command ;
15
15
16
16
//if sub_string == "v1" {
@@ -38,8 +38,20 @@ pub fn generic_sys_call(option: &str, sub_string: &str) -> String {
38
38
result
39
39
//}
40
40
}
41
+
41
42
/// GET /api/v1/historical-price?currency=CURRENCY×tamp=TIMESTAMP
43
+ ///
42
44
/// <https://mempool.space/docs/api/rest#get-historical-price>
45
+ ///
46
+ /// CURRENCY [USD, EUR, GBP, CAD, CHF, AUD, JPY]
47
+ ///
48
+ /// TIMESTAMP [$(date +%s), 1231006505]
49
+ ///
50
+ /// USAGE:
51
+ ///
52
+ /// `mempool-space --historical_price --currency USD --timestamp $(date +%s)`
53
+ ///
54
+ /// `mempool-space_historical_price USD $(date +%s)`
43
55
pub fn historical_price ( currency : & str , timestamp : & str ) {
44
56
let _res = blocking ( & format ! (
45
57
"v1/historical-price?currency={}×tamp={}" ,
@@ -71,7 +83,7 @@ pub fn block_txs(block_hash: &str, start_index: &str) {
71
83
/// <https://mempool.space/docs/api/rest#get-blocks>
72
84
pub fn blocks ( start_height : & str ) {
73
85
//TODO blocks_tip_height
74
- let blocks_tip_height = generic_sys_call ( "blocks_tip_height" , & "extraneous_arg" ) ;
86
+ let blocks_tip_height = api ( "blocks_tip_height" , & "extraneous_arg" ) ;
75
87
let blocks_tip_height_int = blocks_tip_height. parse :: < i32 > ( ) . unwrap_or ( 0 ) ;
76
88
let start_height_int = start_height. parse :: < i32 > ( ) . unwrap_or ( 0 ) ;
77
89
if start_height_int >= 0 && start_height_int <= blocks_tip_height_int {
@@ -91,15 +103,24 @@ pub fn blocks_bulk(min_height: &str, max_height: &str) {
91
103
} else if min_height_int >= 0 && max_height_int >= 0 && min_height_int >= max_height_int {
92
104
let _res = blocking ( & format ! ( "v1/blocks-bulk/{}/{}" , max_height, min_height) ) ;
93
105
} else {
94
- let blocks_tip_height = generic_sys_call ( "blocks_tip_height" , & "extraneous_arg" ) ;
106
+ let blocks_tip_height = api ( "blocks_tip_height" , & "extraneous_arg" ) ;
95
107
let _res = blocking ( & format ! ( "v1/blocks-bulk/{}/{}" , min_height, blocks_tip_height) ) ;
96
108
}
97
109
}
98
110
99
111
/// <https://mempool.space/docs/api/rest>
100
112
/// - [API/REST](https://mempool.space/docs/api/rest)
101
113
/// - [GENERAL](https://mempool.space/docs/api/rest#get-difficulty-adjustment)
114
+ /// - GET /api/v1/difficulty-adjustment \<<https://mempool.space/api/v1/difficulty-adjustment>\>
115
+ /// - GET /api/v1/prices \<<https://mempool.space/api/v1/prices>\>
116
+ /// - GET /api/v1/historical-price?currency=EUR×tamp=1500000000 \<<https://mempool.space/api/v1/historical-price?currency=EUR×tamp=1500000000>\>
102
117
/// - [ADDRESSES](https://mempool.space/docs/api/rest#get-address)
118
+ /// - GET /api/address/:address \<<https://mempool.space/api/address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv>\>
119
+ /// - GET /api/address/:address/txs \<<https://mempool.space/api/address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs>\>
120
+ /// - GET /api/address/:address/txs/chain \<<https://mempool.space/api/address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs/chain>\>
121
+ /// - GET /api/address/:address/txs/mempool \<<https://mempool.space/api/address/1wiz18xYmhRX6xStj2b9t1rwWX4GKUgpv/txs/mempool>\>
122
+ /// - GET /api/address/:address/utxo \<<https://mempool.space/api/address/1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY/utxo>\>
123
+ /// - GET /api/v1/validate-address/:address \<<https://mempool.space/api/v1/validate-address/1KFHE7w8BhaENAswwryaoccDb6qcT6DbYY>\>
103
124
/// - [BLOCKS](https://mempool.space/docs/api/rest#get-block)
104
125
/// - [MINING](https://mempool.space/docs/api/rest#get-mining-pools)
105
126
/// - [FEES](https://mempool.space/docs/api/rest#get-mempool-blocks-fees)
@@ -173,9 +194,14 @@ pub struct Args {
173
194
/// `https://mempool.space/api/blocks/tip/hash`
174
195
pub blocks_tip_hash : Option < String > ,
175
196
176
- /// - BLOCK <BLOCK_HASH> <TXID> <INDEX>
177
- /// `https://mempool.space/api/block/<TXID>/<INDEX>`
197
+ /// `https://mempool.space/api/block/<BLOCK_HASH>/<TXINDEX>`
198
+ ///
199
+ /// mempool-space --block_txid <BLOCK_HASH> --block_txindex <INT>
200
+ ///
201
+ /// mempool-space_block_txid <BLOCK_HASH> <TXINDEX>
202
+ ///
178
203
pub block_txid : Option < String > ,
204
+ ///
179
205
pub block_txindex : Option < String > ,
180
206
181
207
/// - BLOCK <BLOCK_HASH> <TXIDS>
@@ -309,11 +335,11 @@ impl Args {
309
335
// VERSION
310
336
// GENERAL
311
337
if matches. opt_present ( "difficulty_adjustment" ) {
312
- generic_sys_call ( "difficulty_adjustment" , & "v9999" ) ;
338
+ api ( "difficulty_adjustment" , & "v9999" ) ;
313
339
std:: process:: exit ( 0 ) ;
314
340
}
315
341
if matches. opt_present ( "prices" ) {
316
- generic_sys_call ( "prices" , & "v9999" ) ;
342
+ api ( "prices" , & "v9999" ) ;
317
343
std:: process:: exit ( 0 ) ;
318
344
}
319
345
if matches. opt_present ( "historical_price" ) {
@@ -340,67 +366,67 @@ impl Args {
340
366
// ADDRESSES
341
367
if matches. opt_present ( "address" ) {
342
368
let address = matches. opt_str ( "address" ) ;
343
- generic_sys_call ( "address" , & address. unwrap ( ) ) ;
369
+ api ( "address" , & address. unwrap ( ) ) ;
344
370
std:: process:: exit ( 0 ) ;
345
371
}
346
372
if matches. opt_present ( "address_txs" ) {
347
373
let address = matches. opt_str ( "address_txs" ) ;
348
- generic_sys_call ( "address_txs" , & address. unwrap ( ) ) ;
374
+ api ( "address_txs" , & address. unwrap ( ) ) ;
349
375
std:: process:: exit ( 0 ) ;
350
376
}
351
377
if matches. opt_present ( "address_txs_chain" ) {
352
378
let address = matches. opt_str ( "address_txs_chain" ) ;
353
- generic_sys_call ( "address_txs_chain" , & address. unwrap ( ) ) ;
379
+ api ( "address_txs_chain" , & address. unwrap ( ) ) ;
354
380
std:: process:: exit ( 0 ) ;
355
381
}
356
382
if matches. opt_present ( "address_txs_mempool" ) {
357
383
let address = matches. opt_str ( "address_txs_mempool" ) ;
358
- generic_sys_call ( "address_txs_mempool" , & address. unwrap ( ) ) ;
384
+ api ( "address_txs_mempool" , & address. unwrap ( ) ) ;
359
385
std:: process:: exit ( 0 ) ;
360
386
}
361
387
if matches. opt_present ( "validate_address" ) {
362
388
let validate_address = matches. opt_str ( "validate_address" ) ;
363
- generic_sys_call ( "validate_address" , & validate_address. unwrap ( ) ) ;
389
+ api ( "validate_address" , & validate_address. unwrap ( ) ) ;
364
390
std:: process:: exit ( 0 ) ;
365
391
}
366
392
367
393
if matches. opt_present ( "block" ) {
368
394
let block = matches. opt_str ( "block" ) ;
369
- generic_sys_call ( "block" , & block. unwrap ( ) ) ;
395
+ api ( "block" , & block. unwrap ( ) ) ;
370
396
std:: process:: exit ( 0 ) ;
371
397
}
372
398
if matches. opt_present ( "block_header" ) {
373
399
let block_header = matches. opt_str ( "block_header" ) ;
374
- generic_sys_call ( "block_header" , & block_header. unwrap ( ) ) ;
400
+ api ( "block_header" , & block_header. unwrap ( ) ) ;
375
401
std:: process:: exit ( 0 ) ;
376
402
}
377
403
if matches. opt_present ( "block_height" ) {
378
404
let block_height = matches. opt_str ( "block_height" ) ;
379
- generic_sys_call ( "block_height" , & block_height. unwrap ( ) ) ;
405
+ api ( "block_height" , & block_height. unwrap ( ) ) ;
380
406
std:: process:: exit ( 0 ) ;
381
407
}
382
408
//blocks_timestamp
383
409
if matches. opt_present ( "blocks_timestamp" ) {
384
410
let blocks_timestamp = matches. opt_str ( "blocks_timestamp" ) ;
385
- generic_sys_call ( "blocks_timestamp" , & blocks_timestamp. unwrap ( ) ) ;
411
+ api ( "blocks_timestamp" , & blocks_timestamp. unwrap ( ) ) ;
386
412
std:: process:: exit ( 0 ) ;
387
413
}
388
414
if matches. opt_present ( "block_raw" ) {
389
415
let block_raw = matches. opt_str ( "block_raw" ) ;
390
- generic_sys_call ( "block_raw" , & block_raw. unwrap ( ) ) ;
416
+ api ( "block_raw" , & block_raw. unwrap ( ) ) ;
391
417
std:: process:: exit ( 0 ) ;
392
418
}
393
419
if matches. opt_present ( "block_status" ) {
394
420
let block_status = matches. opt_str ( "block_status" ) ;
395
- generic_sys_call ( "block_status" , & block_status. unwrap ( ) ) ;
421
+ api ( "block_status" , & block_status. unwrap ( ) ) ;
396
422
std:: process:: exit ( 0 ) ;
397
423
}
398
424
if matches. opt_present ( "blocks_tip_height" ) {
399
- generic_sys_call ( "blocks_tip_height" , & "extraneous_arg" ) ;
425
+ api ( "blocks_tip_height" , & "extraneous_arg" ) ;
400
426
std:: process:: exit ( 0 ) ;
401
427
}
402
428
if matches. opt_present ( "blocks_tip_hash" ) {
403
- generic_sys_call ( "blocks_tip_hash" , & "extraneous_arg" ) ;
429
+ api ( "blocks_tip_hash" , & "extraneous_arg" ) ;
404
430
std:: process:: exit ( 0 ) ;
405
431
}
406
432
if matches. opt_present ( "block_txid" ) {
0 commit comments