From fe1979420eb6228400c1c818e62fc0ec7998603b Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Sun, 11 Aug 2024 23:10:37 -0400 Subject: [PATCH] src/args.rs:blocks_timestamp --- src/args.rs | 13 ++++++++++--- src/bin/mempool-space_blocks_timestamp.rs | 16 ++++++++++++++++ src/lib.rs | 12 +++++++++++- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 src/bin/mempool-space_blocks_timestamp.rs diff --git a/src/args.rs b/src/args.rs index d3f335a..851b053 100644 --- a/src/args.rs +++ b/src/args.rs @@ -112,7 +112,7 @@ pub struct Args { /// - V1 MINING BLOCKS TIMESTAMP /// `https://mempool.space/api/v1/mining/blocks/timestamp/` - pub block_timestamp: Option, + pub blocks_timestamp: Option, /// - BLOCK /// `https://mempool.space/api/block//raw` @@ -219,6 +219,7 @@ impl Args { opts.optopt("", "block", "block api call", "BLOCK"); opts.optopt("", "block_header", "block-header api call", "BLOCK_HEADER"); opts.optopt("", "block_height", "block-height api call", "BLOCK_HEIGHT"); + opts.optopt("", "blocks_timestamp", "blocks-timestamp api call", "BLOCKS_TIMESTAMP"); //OPTOPT opts.optopt("c", "config", "sets the configuration file", "CONFIG"); @@ -312,6 +313,12 @@ impl Args { generic_sys_call("block_height", &block_height.unwrap()); std::process::exit(0); } + //blocks_timestamp + if matches.opt_present("blocks_timestamp") { + let blocks_timestamp = matches.opt_str("blocks_timestamp"); + generic_sys_call("blocks_timestamp", &blocks_timestamp.unwrap()); + std::process::exit(0); + } if matches.opt_present("h") || (matches.free.is_empty() @@ -380,9 +387,9 @@ impl Args { // https://mempool.space/api/block-height/615615 block_height: matches.opt_str("block_height"), - // V1 MINING BLOCKS + // V1 MINING BLOCKS TIMESTAMP // https://mempool.space/api/v1/mining/blocks/timestamp/" - block_timestamp: matches.opt_str("block_timestamp"), + blocks_timestamp: matches.opt_str("blocks_timestamp"), // BLOCK // https://mempool.space/api/block//raw diff --git a/src/bin/mempool-space_blocks_timestamp.rs b/src/bin/mempool-space_blocks_timestamp.rs new file mode 100644 index 0000000..c5869ba --- /dev/null +++ b/src/bin/mempool-space_blocks_timestamp.rs @@ -0,0 +1,16 @@ +use mempool_space::blocking; +use std::env; + +fn main() { + { + let args: Vec = env::args().collect(); + let mut timestamp = &String::from(""); + if args.len() > 1 { + timestamp = &args[1]; + } else { + // silence is golden + std::process::exit(0); + } + let _res = blocking(&format!("v1/mining/blocks/timestamp/{}", ×tamp)); + } +} diff --git a/src/lib.rs b/src/lib.rs index b484e41..2fd764c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,7 +299,7 @@ mod tests { wait("1"); } fn test_block_height() { - // GET /api/block/:block-height/height + // GET /api/block-height:height let binding = format!("block-height/615615").clone(); let block_height: &str = blocking(&binding).expect("an existing block hash is needed"); let block_height= generic_sys_call( @@ -308,6 +308,16 @@ mod tests { ); wait("1"); } + fn test_timestamp() { + // GET /api/v1/mining/blocks/timestamp/:timestamp + let binding = format!("v1/mining/blocks/timestamp/1672531200").clone(); + let timestamp: &str = blocking(&binding).expect("an existing block hash is needed"); + let timestamp= generic_sys_call( + "timestamp", + "1672531200", + ); + wait("1"); + } #[test] fn test_blockheight() {