Skip to content

Commit 697a075

Browse files
committed
blocks_bulk: TODO: authenticate
1 parent 50a3c43 commit 697a075

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/args.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ pub fn blocks(start_height: &str) {
6363
/// GET /api/v1/blocks-bulk/:minHeight[/:maxHeight]
6464
/// <https://mempool.space/docs/api/rest#get-blocks-bulk>
6565
pub fn blocks_bulk(min_height: &str, max_height: &str) {
66-
//TODO blocks_tip_height
6766
let min_height_int = min_height.parse::<i32>().unwrap_or(0);
6867
let max_height_int = max_height.parse::<i32>().unwrap_or(0);
69-
if min_height_int >= 0 && max_height_int >= 0 && min_height_int <= max_height_int {
68+
if min_height_int >= 0 && max_height_int >= 0 && min_height_int < max_height_int {
7069
let _res = blocking(&format!("v1/blocks-bulk/{}/{}", min_height, max_height));
7170
} else if min_height_int >= 0 && max_height_int >= 0 && min_height_int >= max_height_int {
7271
let _res = blocking(&format!("v1/blocks-bulk/{}/{}", max_height, min_height));
7372
} else {
74-
let blocks_tip_height = api("blocks_tip_height", &"extraneous_arg");
73+
let blocks_tip_height = api::api("blocks_tip_height", &"extraneous_arg");
7574
let _res = blocking(&format!("v1/blocks-bulk/{}/{}", min_height, blocks_tip_height));
7675
}
76+
print!("This API is disabled. Set config.MEMPOOL.MAX_BLOCKS_BULK_QUERY to a positive number to enable it.");
7777
}
7878

7979
/// <https://mempool.space/docs/api/rest>
@@ -261,9 +261,11 @@ pub struct Args {
261261
/// `https://mempool.space/api/v1/blocks/<BLOCKS_START_HEIGHT>`
262262
pub blocks: Option<String>,
263263

264-
/// - V1 BLOCKS_BULK <BLOCK_HEIGHT_START> <BLOCK_HEIGHT_STOP>
265-
/// `https://mempool.space/api/v1/blocks-bulk/<BLOCK_HEIGHT_START>/<BLOCK_HEIGHT_STOP>`
264+
/// - V1 BLOCKS_BULK <MAX_HEIGHT> <MIN_HEIGHT>
265+
/// `https://mempool.space/api/v1/blocks-bulk/<MIN_HEIGHT>/<MAX_HEIGHT>`
266266
pub blocks_bulk: Option<String>,
267+
pub min_height: Option<String>,
268+
pub max_height: Option<String>,
267269

268270
/// Configuration file.
269271
pub config: Option<PathBuf>,
@@ -355,7 +357,10 @@ impl Args {
355357
opts.optopt("", "start_index", "block txs api call", "START_INDEX");
356358

357359
opts.optopt("", "blocks", "block txids api call", "BLOCKS_START_HEIGHT");
358-
opts.optopt("", "blocks_bulk", "block txids api call", "BLOCKS_BULK");
360+
361+
opts.optflag("", "blocks_bulk", "block txids api call");
362+
opts.optopt("", "min_height", "block txids api call", "MIN_HEIGHT");
363+
opts.optopt("", "max_height", "block txids api call", "MAX_HEIGHT");
359364

360365
//OPTOPT
361366
opts.optopt("c", "config", "sets the configuration file", "CONFIG");
@@ -500,6 +505,12 @@ impl Args {
500505
blocks(&arg_blocks.unwrap());
501506
std::process::exit(0);
502507
}
508+
if matches.opt_present("blocks_bulk") {
509+
let arg_min_height = matches.opt_str("min_height"); //expect a integer as string
510+
let arg_max_height = matches.opt_str("max_height"); //expect a integer as string
511+
blocks_bulk(&arg_min_height.unwrap(), &arg_max_height.unwrap());
512+
std::process::exit(0);
513+
}
503514

504515
if matches.opt_present("h")
505516
|| (matches.free.is_empty()
@@ -606,6 +617,8 @@ impl Args {
606617
// V1 BLOCKS_BULK
607618
// https://mempool.space/api/v1/blocks-bulk/<BLOCK_HEIGHT_START>/<BLOCK_HEIGHT_STOP>"
608619
blocks_bulk: matches.opt_str("blocks_bulk"),
620+
min_height: matches.opt_str("min_height"),
621+
max_height: matches.opt_str("max_height"),
609622

610623
server: matches.opt_str("s"),
611624
auth: matches.opt_str("a"),

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@
161161
//! mempool-space \--blocks 730000
162162
//!
163163
//! mempool-space_blocks 730000
164+
//!
165+
//! #### [GET /api/v1/blocks-bulk/:minHeight[/:maxHeight]](https://mempool.space/api/v1/blocks-bulk/100000/100000)
166+
//!
167+
//! mempool-space \--blocks_bulk \--min_height 730000 \--max_height 840000
168+
//!
169+
//! mempool-space_blocks_bulk 730000 840000
164170
165171
#![warn(missing_docs, clippy::unwrap_used)]
166172

@@ -603,8 +609,13 @@ mod tests {
603609
let blocks_tip_height = api("blocks_tip_height", "extraneous_arg");
604610
use crate::args::blocks;
605611
blocks(&"");
612+
wait("1");
606613
blocks(&"0");
614+
wait("1");
615+
blocks(&"25");
616+
wait("1");
607617
blocks(&"730000");
618+
wait("1");
608619
blocks(&blocks_tip_height);
609620
wait("1");
610621
}
@@ -622,6 +633,7 @@ mod tests {
622633
blocks_bulk(&"0", &"0");
623634
blocks_bulk(&"0", &"1");
624635
blocks_bulk(&"730000", &"840000");
636+
blocks_bulk(&"730000", &blocks_tip_height);
625637
wait("1");
626638
}
627639
#[test]

0 commit comments

Comments
 (0)