@@ -19,18 +19,31 @@ const URL: &str = "https://mempool.space/api";
19
19
20
20
/// `pub fn blocking(api: &String) -> Result<&str>`
21
21
pub fn blocking ( api : & String ) -> Result < & str > {
22
+ //print!("api={}", api);
22
23
let call = format ! ( "{}/{}" , URL , api) ;
23
24
let mut body = ureq:: get ( & call)
24
25
. call ( )
25
26
. expect ( "calls to blocking(api: &String) needs to include /v1/<api_endpoint> in some cases." )
26
27
. into_reader ( ) ;
27
28
let mut buf = Vec :: new ( ) ;
28
29
body. read_to_end ( & mut buf) . unwrap ( ) ;
29
- let text = match std:: str:: from_utf8 ( & buf) {
30
- Ok ( s) => s,
31
- Err ( _) => panic ! ( "Invalid ASCII data" ) ,
32
- } ;
33
- print ! ( "{}" , text) ;
30
+ if !api. ends_with ( "raw" ) {
31
+ //print!("!api.ends_with raw");
32
+ let text = match std:: str:: from_utf8 ( & buf) {
33
+ Ok ( s) => s,
34
+ Err ( _) => panic ! ( "Invalid ASCII data" ) ,
35
+ } ;
36
+ print ! ( "{}" , text) ;
37
+ } else {
38
+ if api. ends_with ( "raw" ) {
39
+ //print!("api.ends_with raw");
40
+ print ! ( "{:?}" , & buf) ;
41
+ }
42
+ if api. ends_with ( "something_else" ) {
43
+ //print!("api.ends_with something_else");
44
+ print ! ( "{:?}" , & buf) ;
45
+ }
46
+ }
34
47
Ok ( api)
35
48
}
36
49
@@ -302,22 +315,26 @@ mod tests {
302
315
// GET /api/block-height:height
303
316
let binding = format ! ( "block-height/615615" ) . clone ( ) ;
304
317
let block_height: & str = blocking ( & binding) . expect ( "an existing block hash is needed" ) ;
305
- let block_height= generic_sys_call (
306
- "block_height" ,
307
- "615615" ,
308
- ) ;
318
+ let block_height = generic_sys_call ( "block_height" , "615615" ) ;
309
319
wait ( "1" ) ;
310
320
}
311
- fn test_timestamp ( ) {
321
+ fn test_blocks_timestamp ( ) {
312
322
// GET /api/v1/mining/blocks/timestamp/:timestamp
313
323
let binding = format ! ( "v1/mining/blocks/timestamp/1672531200" ) . clone ( ) ;
314
324
let timestamp: & str = blocking ( & binding) . expect ( "an existing block hash is needed" ) ;
315
- let timestamp= generic_sys_call (
316
- "timestamp" ,
317
- "1672531200" ,
318
- ) ;
325
+ let timestamp = generic_sys_call ( "blocks_timestamp" , "1672531200" ) ;
319
326
wait ( "1" ) ;
320
327
}
328
+ fn test_block_raw ( ) {
329
+ // GET /api/block/:hash/raw
330
+ let binding = format ! ( "block/0000000000000000000065bda8f8a88f2e1e00d9a6887a43d640e52a4c7660f2" ) . clone ( ) ;
331
+ let block_raw: & str = blocking ( & binding) . expect ( "an existing block hash is needed" ) ;
332
+ let block_raw = generic_sys_call (
333
+ "block_raw" ,
334
+ "0000000000000000000065bda8f8a88f2e1e00d9a6887a43d640e52a4c7660f2" ,
335
+ ) ;
336
+ wait ( "100" ) ;
337
+ }
321
338
322
339
#[ test]
323
340
fn test_blockheight ( ) {
0 commit comments