@@ -71,13 +71,30 @@ pub fn block_txs(block_hash: &str, start_index: &str) {
71
71
/// <https://mempool.space/docs/api/rest#get-blocks>
72
72
pub fn blocks ( start_height : & str ) {
73
73
//TODO blocks_tip_height
74
+ let blocks_tip_height = generic_sys_call ( "blocks_tip_height" , & "extraneous_arg" ) ;
75
+ let blocks_tip_height_int = blocks_tip_height. parse :: < i32 > ( ) . unwrap_or ( 0 ) ;
74
76
let start_height_int = start_height. parse :: < i32 > ( ) . unwrap_or ( 0 ) ;
75
- if start_height_int >= 0 {
77
+ if start_height_int >= 0 && start_height_int <= blocks_tip_height_int {
76
78
let _res = blocking ( & format ! ( "v1/blocks/{}" , start_height) ) ;
77
79
} else {
78
80
let _res = blocking ( & format ! ( "v1/blocks" ) ) ;
79
81
}
80
82
}
83
+ /// GET /api/v1/blocks-bulk/:minHeight[/:maxHeight]
84
+ /// <https://mempool.space/docs/api/rest#get-blocks-bulk>
85
+ pub fn blocks_bulk ( min_height : & str , max_height : & str ) {
86
+ //TODO blocks_tip_height
87
+ let min_height_int = min_height. parse :: < i32 > ( ) . unwrap_or ( 0 ) ;
88
+ let max_height_int = max_height. parse :: < i32 > ( ) . unwrap_or ( 0 ) ;
89
+ if min_height_int >= 0 && max_height_int >= 0 && min_height_int <= max_height_int {
90
+ let _res = blocking ( & format ! ( "v1/blocks-bulk/{}/{}" , min_height, max_height) ) ;
91
+ } else if min_height_int >= 0 && max_height_int >= 0 && min_height_int >= max_height_int {
92
+ let _res = blocking ( & format ! ( "v1/blocks-bulk/{}/{}" , max_height, min_height) ) ;
93
+ } else {
94
+ let blocks_tip_height = generic_sys_call ( "blocks_tip_height" , & "extraneous_arg" ) ;
95
+ let _res = blocking ( & format ! ( "v1/blocks-bulk/{}/{}" , min_height, blocks_tip_height) ) ;
96
+ }
97
+ }
81
98
82
99
/// <https://mempool.space/docs/api/rest>
83
100
/// - [API/REST](https://mempool.space/docs/api/rest)
0 commit comments