Skip to content

Commit ec2a3e8

Browse files
committed
src/args.rs:blockheight.rs:lib.rs:more documentation
1 parent 5373069 commit ec2a3e8

File tree

3 files changed

+85
-67
lines changed

3 files changed

+85
-67
lines changed

src/args.rs

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use std::process;
66

77
use crate::blocking;
88

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 {
1414
use std::process::Command;
1515

1616
//if sub_string == "v1" {
@@ -38,8 +38,20 @@ pub fn generic_sys_call(option: &str, sub_string: &str) -> String {
3838
result
3939
//}
4040
}
41+
4142
/// GET /api/v1/historical-price?currency=CURRENCY&timestamp=TIMESTAMP
43+
///
4244
/// <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)`
4355
pub fn historical_price(currency: &str, timestamp: &str) {
4456
let _res = blocking(&format!(
4557
"v1/historical-price?currency={}&timestamp={}",
@@ -71,7 +83,7 @@ pub fn block_txs(block_hash: &str, start_index: &str) {
7183
/// <https://mempool.space/docs/api/rest#get-blocks>
7284
pub fn blocks(start_height: &str) {
7385
//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");
7587
let blocks_tip_height_int = blocks_tip_height.parse::<i32>().unwrap_or(0);
7688
let start_height_int = start_height.parse::<i32>().unwrap_or(0);
7789
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) {
91103
} else if min_height_int >= 0 && max_height_int >= 0 && min_height_int >= max_height_int {
92104
let _res = blocking(&format!("v1/blocks-bulk/{}/{}", max_height, min_height));
93105
} 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");
95107
let _res = blocking(&format!("v1/blocks-bulk/{}/{}", min_height, blocks_tip_height));
96108
}
97109
}
98110

99111
/// <https://mempool.space/docs/api/rest>
100112
/// - [API/REST](https://mempool.space/docs/api/rest)
101113
/// - [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&timestamp=1500000000 \<<https://mempool.space/api/v1/historical-price?currency=EUR&timestamp=1500000000>\>
102117
/// - [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>\>
103124
/// - [BLOCKS](https://mempool.space/docs/api/rest#get-block)
104125
/// - [MINING](https://mempool.space/docs/api/rest#get-mining-pools)
105126
/// - [FEES](https://mempool.space/docs/api/rest#get-mempool-blocks-fees)
@@ -173,9 +194,14 @@ pub struct Args {
173194
/// `https://mempool.space/api/blocks/tip/hash`
174195
pub blocks_tip_hash: Option<String>,
175196

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+
///
178203
pub block_txid: Option<String>,
204+
///
179205
pub block_txindex: Option<String>,
180206

181207
/// - BLOCK <BLOCK_HASH> <TXIDS>
@@ -309,11 +335,11 @@ impl Args {
309335
// VERSION
310336
// GENERAL
311337
if matches.opt_present("difficulty_adjustment") {
312-
generic_sys_call("difficulty_adjustment", &"v9999");
338+
api("difficulty_adjustment", &"v9999");
313339
std::process::exit(0);
314340
}
315341
if matches.opt_present("prices") {
316-
generic_sys_call("prices", &"v9999");
342+
api("prices", &"v9999");
317343
std::process::exit(0);
318344
}
319345
if matches.opt_present("historical_price") {
@@ -340,67 +366,67 @@ impl Args {
340366
// ADDRESSES
341367
if matches.opt_present("address") {
342368
let address = matches.opt_str("address");
343-
generic_sys_call("address", &address.unwrap());
369+
api("address", &address.unwrap());
344370
std::process::exit(0);
345371
}
346372
if matches.opt_present("address_txs") {
347373
let address = matches.opt_str("address_txs");
348-
generic_sys_call("address_txs", &address.unwrap());
374+
api("address_txs", &address.unwrap());
349375
std::process::exit(0);
350376
}
351377
if matches.opt_present("address_txs_chain") {
352378
let address = matches.opt_str("address_txs_chain");
353-
generic_sys_call("address_txs_chain", &address.unwrap());
379+
api("address_txs_chain", &address.unwrap());
354380
std::process::exit(0);
355381
}
356382
if matches.opt_present("address_txs_mempool") {
357383
let address = matches.opt_str("address_txs_mempool");
358-
generic_sys_call("address_txs_mempool", &address.unwrap());
384+
api("address_txs_mempool", &address.unwrap());
359385
std::process::exit(0);
360386
}
361387
if matches.opt_present("validate_address") {
362388
let validate_address = matches.opt_str("validate_address");
363-
generic_sys_call("validate_address", &validate_address.unwrap());
389+
api("validate_address", &validate_address.unwrap());
364390
std::process::exit(0);
365391
}
366392

367393
if matches.opt_present("block") {
368394
let block = matches.opt_str("block");
369-
generic_sys_call("block", &block.unwrap());
395+
api("block", &block.unwrap());
370396
std::process::exit(0);
371397
}
372398
if matches.opt_present("block_header") {
373399
let block_header = matches.opt_str("block_header");
374-
generic_sys_call("block_header", &block_header.unwrap());
400+
api("block_header", &block_header.unwrap());
375401
std::process::exit(0);
376402
}
377403
if matches.opt_present("block_height") {
378404
let block_height = matches.opt_str("block_height");
379-
generic_sys_call("block_height", &block_height.unwrap());
405+
api("block_height", &block_height.unwrap());
380406
std::process::exit(0);
381407
}
382408
//blocks_timestamp
383409
if matches.opt_present("blocks_timestamp") {
384410
let blocks_timestamp = matches.opt_str("blocks_timestamp");
385-
generic_sys_call("blocks_timestamp", &blocks_timestamp.unwrap());
411+
api("blocks_timestamp", &blocks_timestamp.unwrap());
386412
std::process::exit(0);
387413
}
388414
if matches.opt_present("block_raw") {
389415
let block_raw = matches.opt_str("block_raw");
390-
generic_sys_call("block_raw", &block_raw.unwrap());
416+
api("block_raw", &block_raw.unwrap());
391417
std::process::exit(0);
392418
}
393419
if matches.opt_present("block_status") {
394420
let block_status = matches.opt_str("block_status");
395-
generic_sys_call("block_status", &block_status.unwrap());
421+
api("block_status", &block_status.unwrap());
396422
std::process::exit(0);
397423
}
398424
if matches.opt_present("blocks_tip_height") {
399-
generic_sys_call("blocks_tip_height", &"extraneous_arg");
425+
api("blocks_tip_height", &"extraneous_arg");
400426
std::process::exit(0);
401427
}
402428
if matches.opt_present("blocks_tip_hash") {
403-
generic_sys_call("blocks_tip_hash", &"extraneous_arg");
429+
api("blocks_tip_hash", &"extraneous_arg");
404430
std::process::exit(0);
405431
}
406432
if matches.opt_present("block_txid") {

src/blockheight.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,21 @@ use std::time::SystemTime;
33

44
use reqwest::Url;
55

6-
pub fn check_curl() {
7-
8-
// println!("check_curl");
9-
}
10-
6+
/// function example
117
pub fn blockheight() -> Result<f64, ascii::AsciiChar> {
128
let since_the_epoch = SystemTime::now()
139
.duration_since(SystemTime::UNIX_EPOCH)
1410
.expect("get millis error");
1511
let seconds = since_the_epoch.as_secs();
1612
let subsec_millis = since_the_epoch.subsec_millis() as u64;
1713
let _now_millis = seconds * 1000 + subsec_millis;
18-
// println!("now millis: {}", seconds * 1000 + subsec_millis);
19-
20-
// let bh = get_blockheight();
21-
// println!("{}",bh.unwrap());
2214
let url = Url::parse("https://mempool.space/api/blocks/tip/height").unwrap();
2315
let mut res = reqwest::blocking::get(url).unwrap();
2416

2517
let mut tmp_string = String::new();
2618
res.read_to_string(&mut tmp_string).unwrap();
2719
let tmp_u64 = tmp_string.parse::<u64>().unwrap_or(0);
2820

29-
// TODO:impl gnostr-weeble_millis
30-
// let weeble = now_millis as f64 / tmp_u64 as f64;
31-
// let blockheight = seconds as f64 / tmp_u64 as f64;
3221
let blockheight = tmp_u64 as f64;
33-
// return Ok(blockheight.floor());
3422
return Ok(blockheight);
3523
}

0 commit comments

Comments
 (0)