@@ -10,32 +10,33 @@ use crate::blocking;
10
10
/// mempool-space --arg
11
11
/// mempool-space_ARG_STRING
12
12
/// mempool-space --arg_string
13
- pub fn generic_sys_call ( option : & str , sub_string : & str ) {
13
+ pub fn generic_sys_call ( option : & str , sub_string : & str ) -> String {
14
14
use std:: process:: Command ;
15
15
16
- if sub_string == "v1" {
17
- print ! ( "TODO: support --version v1 api versioning." )
18
- } else if sub_string == "v2" {
19
- print ! ( "TODO: support --version v2 api versioning." )
16
+ //if sub_string == "v1" {
17
+ // print!("TODO: support --version v1 api versioning.");
18
+ //} else if sub_string == "v2" {
19
+ // print!("TODO: support --version v2 api versioning.");
20
+ //} else {
21
+ let output = if cfg ! ( target_os = "windows" ) {
22
+ Command :: new ( format ! ( "mempool-space_{}" , option) )
23
+ . args ( [ "/C" , sub_string] )
24
+ . output ( )
25
+ . expect ( "failed to execute process" )
20
26
} else {
21
- let output = if cfg ! ( target_os = "windows" ) {
22
- Command :: new ( format ! ( "mempool-space_{}" , option) )
23
- . args ( [ "/C" , sub_string] )
24
- . output ( )
25
- . expect ( "failed to execute process" )
26
- } else {
27
- Command :: new ( format ! ( "mempool-space_{}" , option) )
28
- . arg ( sub_string)
29
- //.arg("echo hello")
30
- . output ( )
31
- . expect ( "failed to execute process" )
32
- } ;
33
-
34
- let result = String :: from_utf8 ( output. stdout )
35
- . map_err ( |non_utf8| String :: from_utf8_lossy ( non_utf8. as_bytes ( ) ) . into_owned ( ) )
36
- . unwrap ( ) ;
37
- print ! ( "{}" , result) ;
38
- }
27
+ Command :: new ( format ! ( "mempool-space_{}" , option) )
28
+ . arg ( sub_string)
29
+ //.arg("echo hello")
30
+ . output ( )
31
+ . expect ( "failed to execute process" )
32
+ } ;
33
+
34
+ let result = String :: from_utf8 ( output. stdout )
35
+ . map_err ( |non_utf8| String :: from_utf8_lossy ( non_utf8. as_bytes ( ) ) . into_owned ( ) )
36
+ . unwrap ( ) ;
37
+ print ! ( "{}" , result) ;
38
+ result
39
+ //}
39
40
}
40
41
/// GET /api/v1/historical-price?currency=CURRENCY×tamp=TIMESTAMP
41
42
/// <https://mempool.space/docs/api/rest#get-historical-price>
@@ -66,6 +67,17 @@ pub fn block_txs(block_hash: &str, start_index: &str) {
66
67
let _res = blocking ( & format ! ( "block/{}/txs/{}" , block_hash, & "0" ) ) ;
67
68
}
68
69
}
70
+ /// GET /api/v1/blocks[/:startHeight]
71
+ /// <https://mempool.space/docs/api/rest#get-blocks>
72
+ pub fn blocks ( start_height : & str ) {
73
+ //TODO blocks_tip_height
74
+ let start_height_int = start_height. parse :: < i32 > ( ) . unwrap_or ( 0 ) ;
75
+ if start_height_int >= 0 {
76
+ let _res = blocking ( & format ! ( "v1/blocks/{}" , start_height) ) ;
77
+ } else {
78
+ let _res = blocking ( & format ! ( "v1/blocks" ) ) ;
79
+ }
80
+ }
69
81
70
82
/// <https://mempool.space/docs/api/rest>
71
83
/// - [API/REST](https://mempool.space/docs/api/rest)
@@ -159,8 +171,9 @@ pub struct Args {
159
171
pub block_start_index : Option < String > ,
160
172
161
173
/// - V1 BLOCKS <BLOCK_HEIGHT>
162
- /// `https://mempool.space/api/v1/blocks/<BLOCK_HEIGHT >`
174
+ /// `https://mempool.space/api/v1/blocks/<BLOCKS_START_HEIGHT >`
163
175
pub blocks : Option < String > ,
176
+
164
177
/// - V1 BLOCKS_BULK <BLOCK_HEIGHT_START> <BLOCK_HEIGHT_STOP>
165
178
/// `https://mempool.space/api/v1/blocks-bulk/<BLOCK_HEIGHT_START>/<BLOCK_HEIGHT_STOP>`
166
179
pub blocks_bulk : Option < String > ,
@@ -254,7 +267,7 @@ impl Args {
254
267
opts. optopt ( "" , "block_txs" , "block txs api call" , "BLOCK_TXS" ) ;
255
268
opts. optopt ( "" , "block_start_index" , "block txs api call" , "BLOCK_START_INDEX" ) ;
256
269
257
- opts. optopt ( "" , "blocks" , "block txids api call" , "BLOCKS " ) ;
270
+ opts. optopt ( "" , "blocks" , "block txids api call" , "BLOCKS_START_HEIGHT " ) ;
258
271
opts. optopt ( "" , "blocks_bulk" , "block txids api call" , "BLOCKS_BULK" ) ;
259
272
260
273
//OPTOPT
@@ -390,6 +403,11 @@ impl Args {
390
403
block_txs ( & arg_block_txs. unwrap ( ) , & arg_block_start_index. unwrap ( ) ) ;
391
404
std:: process:: exit ( 0 ) ;
392
405
}
406
+ if matches. opt_present ( "blocks" ) {
407
+ let arg_blocks = matches. opt_str ( "blocks" ) ; //expect a integer as string
408
+ blocks ( & arg_blocks. unwrap ( ) ) ;
409
+ std:: process:: exit ( 0 ) ;
410
+ }
393
411
394
412
if matches. opt_present ( "h" )
395
413
|| ( matches. free . is_empty ( )
@@ -492,6 +510,7 @@ impl Args {
492
510
// V1 BLOCKS
493
511
// https://mempool.space/api/v1/blocks/<BLOCK_HEIGHT>"
494
512
blocks : matches. opt_str ( "blocks" ) ,
513
+
495
514
// V1 BLOCKS_BULK
496
515
// https://mempool.space/api/v1/blocks-bulk/<BLOCK_HEIGHT_START>/<BLOCK_HEIGHT_STOP>"
497
516
blocks_bulk : matches. opt_str ( "blocks_bulk" ) ,
0 commit comments