Skip to content

Commit fe19794

Browse files
committed
src/args.rs:blocks_timestamp
1 parent 3f78e08 commit fe19794

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/args.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub struct Args {
112112

113113
/// - V1 MINING BLOCKS TIMESTAMP <UTC_SECS>
114114
/// `https://mempool.space/api/v1/mining/blocks/timestamp/<UTC_SECS>`
115-
pub block_timestamp: Option<String>,
115+
pub blocks_timestamp: Option<String>,
116116

117117
/// - BLOCK
118118
/// `https://mempool.space/api/block/<BLOCK_HASH>/raw`
@@ -219,6 +219,7 @@ impl Args {
219219
opts.optopt("", "block", "block api call", "BLOCK");
220220
opts.optopt("", "block_header", "block-header api call", "BLOCK_HEADER");
221221
opts.optopt("", "block_height", "block-height api call", "BLOCK_HEIGHT");
222+
opts.optopt("", "blocks_timestamp", "blocks-timestamp api call", "BLOCKS_TIMESTAMP");
222223

223224
//OPTOPT
224225
opts.optopt("c", "config", "sets the configuration file", "CONFIG");
@@ -312,6 +313,12 @@ impl Args {
312313
generic_sys_call("block_height", &block_height.unwrap());
313314
std::process::exit(0);
314315
}
316+
//blocks_timestamp
317+
if matches.opt_present("blocks_timestamp") {
318+
let blocks_timestamp = matches.opt_str("blocks_timestamp");
319+
generic_sys_call("blocks_timestamp", &blocks_timestamp.unwrap());
320+
std::process::exit(0);
321+
}
315322

316323
if matches.opt_present("h")
317324
|| (matches.free.is_empty()
@@ -380,9 +387,9 @@ impl Args {
380387
// https://mempool.space/api/block-height/615615
381388
block_height: matches.opt_str("block_height"),
382389

383-
// V1 MINING BLOCKS
390+
// V1 MINING BLOCKS TIMESTAMP
384391
// https://mempool.space/api/v1/mining/blocks/timestamp/<UTC_SECS>"
385-
block_timestamp: matches.opt_str("block_timestamp"),
392+
blocks_timestamp: matches.opt_str("blocks_timestamp"),
386393

387394
// BLOCK
388395
// https://mempool.space/api/block/<block_hash>/raw
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use mempool_space::blocking;
2+
use std::env;
3+
4+
fn main() {
5+
{
6+
let args: Vec<String> = env::args().collect();
7+
let mut timestamp = &String::from("");
8+
if args.len() > 1 {
9+
timestamp = &args[1];
10+
} else {
11+
// silence is golden
12+
std::process::exit(0);
13+
}
14+
let _res = blocking(&format!("v1/mining/blocks/timestamp/{}", &timestamp));
15+
}
16+
}

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ mod tests {
299299
wait("1");
300300
}
301301
fn test_block_height() {
302-
// GET /api/block/:block-height/height
302+
// GET /api/block-height:height
303303
let binding = format!("block-height/615615").clone();
304304
let block_height: &str = blocking(&binding).expect("an existing block hash is needed");
305305
let block_height= generic_sys_call(
@@ -308,6 +308,16 @@ mod tests {
308308
);
309309
wait("1");
310310
}
311+
fn test_timestamp() {
312+
// GET /api/v1/mining/blocks/timestamp/:timestamp
313+
let binding = format!("v1/mining/blocks/timestamp/1672531200").clone();
314+
let timestamp: &str = blocking(&binding).expect("an existing block hash is needed");
315+
let timestamp= generic_sys_call(
316+
"timestamp",
317+
"1672531200",
318+
);
319+
wait("1");
320+
}
311321

312322
#[test]
313323
fn test_blockheight() {

0 commit comments

Comments
 (0)