@@ -6,6 +6,10 @@ 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
9
13
pub fn generic_sys_call ( option : & str , sub_string : & str ) {
10
14
use std:: process:: Command ;
11
15
@@ -33,36 +37,35 @@ pub fn generic_sys_call(option: &str, sub_string: &str) {
33
37
print ! ( "{}" , result) ;
34
38
}
35
39
}
36
-
40
+ /// GET /api/v1/historical-price?currency=CURRENCY×tamp=TIMESTAMP
37
41
/// <https://mempool.space/docs/api/rest#get-historical-price>
38
42
pub fn historical_price ( currency : & str , timestamp : & str ) {
39
- //REF: mempool-space --historical_price --currency EUR --timestamp 150000000
40
- //EXPECT: {"prices":[{"time":1279497600,"EUR":0,"USD":0}],"exchangeRates":{"USDEUR":0.92,"USDGBP":0.78,"USDCAD":1.38,"USDCHF":0.87,"USDAUD":1.52,"USDJPY":146.79}}
41
43
let _res = blocking ( & format ! (
42
44
"v1/historical-price?currency={}×tamp={}" ,
43
45
& format!( "{:}" , & currency) ,
44
46
& format!( "{:}" , & timestamp)
45
47
) ) ;
46
48
}
47
- //GET /api/block/:hash/txid/:index
48
- //https://mempool.space/docs/api/rest#get-block-transaction-id
49
- pub fn block_tx_id ( block_hash : & str , txindex : & str ) {
50
- //REF: mempool-space --block_txid 000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce --txindex 218
51
- //EXPECT: 0fa6da60e484941f255cbb025c3d6440e5a7e970119e899b4065c7999360e406
49
+ /// GET /api/block/:hash/txid/:index
50
+ /// <https://mempool.space/docs/api/rest#get-block-transaction-id>
51
+ pub fn block_txid ( block_hash : & str , txindex : & str ) {
52
52
let _res = blocking ( & format ! ( "block/{}/txid/{}" , block_hash, txindex) ) ;
53
53
}
54
- //GET /api/block/:hash/txids
55
- //https://mempool.space/docs/api/rest#get-block-transaction-ids
56
- pub fn block_tx_ids ( block_hash : & str ) {
57
- //REF: mempool-space --block_txids 000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce
58
- //EXPECT:
59
- // [
60
- // "cfe624ccdd8010cf78dbedd1b25e1ff601b470c4d7d90fa9fc8c1bcc5cdc6e0e",
61
- // "a5ef89881bd5103f223a0fa285dfc75f4718974cb792cf85e623a7de05801bc9",
62
- // ...,
63
- // ]
54
+ /// GET /api/block/:hash/txids
55
+ /// <https://mempool.space/docs/api/rest#get-block-transaction-ids>
56
+ pub fn block_txids ( block_hash : & str ) {
64
57
let _res = blocking ( & format ! ( "block/{}/txids" , block_hash) ) ;
65
58
}
59
+ /// GET /api/block/:hash/txs[/:start_index] (start_index % 25 = 0)
60
+ /// <https://mempool.space/docs/api/rest#get-block-transactions>
61
+ pub fn block_txs ( block_hash : & str , start_index : & str ) {
62
+ let start_index_int = start_index. parse :: < i32 > ( ) . unwrap_or ( 0 ) ;
63
+ if start_index_int % 25 == 0 {
64
+ let _res = blocking ( & format ! ( "block/{}/txs/{}" , block_hash, start_index) ) ;
65
+ } else {
66
+ let _res = blocking ( & format ! ( "block/{}/txs/{}" , block_hash, & "0" ) ) ;
67
+ }
68
+ }
66
69
67
70
/// <https://mempool.space/docs/api/rest>
68
71
/// - [API/REST](https://mempool.space/docs/api/rest)
@@ -153,6 +156,8 @@ pub struct Args {
153
156
/// - BLOCK <BLOCK_HASH> <TXS>
154
157
/// `https://mempool.space/api/block/<BLOCK_HASH>/txs`
155
158
pub block_txs : Option < String > ,
159
+ pub block_start_index : Option < String > ,
160
+
156
161
/// - V1 BLOCKS <BLOCK_HEIGHT>
157
162
/// `https://mempool.space/api/v1/blocks/<BLOCK_HEIGHT>`
158
163
pub blocks : Option < String > ,
@@ -244,9 +249,11 @@ impl Args {
244
249
245
250
opts. optopt ( "" , "block_txid" , "block txid api call" , "BLOCK_TXID" ) ;
246
251
opts. optopt ( "" , "block_txindex" , "block_txindex api call" , "BLOCK_TXINDEX" ) ;
247
-
248
252
opts. optopt ( "" , "block_txids" , "block txids api call" , "BLOCK_TXIDS" ) ;
249
- opts. optopt ( "" , "block_txs" , "block txids api call" , "BLOCK_TXS" ) ;
253
+
254
+ opts. optopt ( "" , "block_txs" , "block txs api call" , "BLOCK_TXS" ) ;
255
+ opts. optopt ( "" , "block_start_index" , "block txs api call" , "BLOCK_START_INDEX" ) ;
256
+
250
257
opts. optopt ( "" , "blocks" , "block txids api call" , "BLOCKS" ) ;
251
258
opts. optopt ( "" , "blocks_bulk" , "block txids api call" , "BLOCKS_BULK" ) ;
252
259
@@ -367,16 +374,23 @@ impl Args {
367
374
std:: process:: exit ( 0 ) ;
368
375
}
369
376
if matches. opt_present ( "block_txid" ) {
370
- let block_txid = matches. opt_str ( "block_txid" ) ; //expect a block_hash
371
- let block_txindex = matches. opt_str ( "block_txindex" ) ;
372
- block_tx_id ( & block_txid . unwrap ( ) , & block_txindex . unwrap ( ) ) ;
377
+ let arg_block_txid = matches. opt_str ( "block_txid" ) ; //expect a block_hash
378
+ let arg_block_txindex = matches. opt_str ( "block_txindex" ) ;
379
+ block_txid ( & arg_block_txid . unwrap ( ) , & arg_block_txindex . unwrap ( ) ) ;
373
380
std:: process:: exit ( 0 ) ;
374
381
}
375
382
if matches. opt_present ( "block_txids" ) {
376
- let block_txids = matches. opt_str ( "block_txids" ) ; //expect a block_hash
377
- block_tx_ids ( & block_txids . unwrap ( ) ) ;
383
+ let arg_block_txids = matches. opt_str ( "block_txids" ) ; //expect a block_hash
384
+ block_txids ( & arg_block_txids . unwrap ( ) ) ;
378
385
std:: process:: exit ( 0 ) ;
379
386
}
387
+ if matches. opt_present ( "block_txs" ) {
388
+ let arg_block_txs = matches. opt_str ( "block_txs" ) ; //expect a block_hash
389
+ let arg_block_start_index = matches. opt_str ( "block_start_index" ) ;
390
+ block_txs ( & arg_block_txs. unwrap ( ) , & arg_block_start_index. unwrap ( ) ) ;
391
+ std:: process:: exit ( 0 ) ;
392
+ }
393
+
380
394
if matches. opt_present ( "h" )
381
395
|| ( matches. free . is_empty ( )
382
396
&& !matches. opt_present ( "u" )
@@ -473,6 +487,7 @@ impl Args {
473
487
// BLOCK BLOCK_HASH TXS
474
488
// https://mempool.space/api/block/<block_hash>/<txs>
475
489
block_txs : matches. opt_str ( "block_txs" ) ,
490
+ block_start_index : matches. opt_str ( "block_start_index" ) ,
476
491
477
492
// V1 BLOCKS
478
493
// https://mempool.space/api/v1/blocks/<BLOCK_HEIGHT>"
0 commit comments