Skip to content

Commit

Permalink
src/args.rs:blocks_timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyMcMillan committed Aug 12, 2024
1 parent 3f78e08 commit fe19794
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct Args {

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

/// - BLOCK
/// `https://mempool.space/api/block/<BLOCK_HASH>/raw`
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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/<UTC_SECS>"
block_timestamp: matches.opt_str("block_timestamp"),
blocks_timestamp: matches.opt_str("blocks_timestamp"),

// BLOCK
// https://mempool.space/api/block/<block_hash>/raw
Expand Down
16 changes: 16 additions & 0 deletions src/bin/mempool-space_blocks_timestamp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use mempool_space::blocking;
use std::env;

fn main() {
{
let args: Vec<String> = 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/{}", &timestamp));
}
}
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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() {
Expand Down

0 comments on commit fe19794

Please sign in to comment.