|
7 | 7 | // Author: Simon Brummer ([email protected])
|
8 | 8 |
|
9 | 9 | #![warn(missing_docs, clippy::unwrap_used)]
|
10 |
| -//! mempool_space, a mempool.space API lib. |
11 |
| -//! |
12 |
| -//! Author: @RandyMcMillan ([email protected]) |
13 |
| -//! |
14 |
| -//! <https://github.com/RandyMcMillan/mempool_space.git> |
15 |
| -
|
16 |
| -//! |
17 |
| -//! USAGE: |
18 |
| -//! - mempool-space \--difficulty_adjustment (flagged) |
19 |
| -//! - mempool-space_difficulty_adjustment (executable) |
20 |
| -//! 1. Flags follow the mempool.space api/rest (replace dashes with underscores) |
21 |
| -//! 2. Flags invoke the executable |
22 |
| -
|
23 | 10 | use std::io::Read;
|
24 |
| - |
25 |
| -//const API_VERSION: &str = "v1"; |
26 |
| -// |
| 11 | +const API_VERSION: &str = "v1"; |
27 | 12 | const URL: &str = "https://mempool.space/api";
|
28 | 13 |
|
| 14 | +/// mempool_space - a mempool.space API lib |
| 15 | +/// |
| 16 | +/// Author: @RandyMcMillan ([email protected]) |
| 17 | +/// |
| 18 | +/// <https://github.com/RandyMcMillan/mempool_space.git> |
| 19 | +
|
| 20 | +/// |
| 21 | +/// USAGE: |
| 22 | +/// - mempool-space \--difficulty_adjustment (flagged) |
| 23 | +/// - mempool-space_difficulty_adjustment (executable) |
| 24 | +/// 1. Flags follow the mempool.space api/rest (replace dashes with underscores) |
| 25 | +/// 2. Flags invoke the executable |
| 26 | +
|
| 27 | +/// |
| 28 | +
|
| 29 | +/// `pub fn api(option: &str, sub_string: &str) -> String` |
| 30 | +/// |
| 31 | +pub fn api(option: &str, sub_string: &str) -> String { |
| 32 | + use std::process::Command; |
| 33 | + |
| 34 | + //if sub_string == "v1" { |
| 35 | + // print!("TODO: support --version v1 api versioning."); |
| 36 | + //} else if sub_string == "v2" { |
| 37 | + // print!("TODO: support --version v2 api versioning."); |
| 38 | + //} else { |
| 39 | + let output = if cfg!(target_os = "windows") { |
| 40 | + Command::new(format!("mempool-space_{}", option)) |
| 41 | + .args(["/C", sub_string]) |
| 42 | + .output() |
| 43 | + .expect("failed to execute process") |
| 44 | + } else { |
| 45 | + Command::new(format!("mempool-space_{}", option)) |
| 46 | + .arg(sub_string) |
| 47 | + //.arg("echo hello") |
| 48 | + .output() |
| 49 | + .expect("failed to execute process") |
| 50 | + }; |
| 51 | + |
| 52 | + let result = String::from_utf8(output.stdout) |
| 53 | + .map_err(|non_utf8| String::from_utf8_lossy(non_utf8.as_bytes()).into_owned()) |
| 54 | + .unwrap(); |
| 55 | + print!("{}", result); |
| 56 | + result |
| 57 | + //} |
| 58 | +} |
| 59 | +/// mempool_space - a mempool.space API lib |
| 60 | +/// |
| 61 | +/// Author: @RandyMcMillan ([email protected]) |
| 62 | +/// |
| 63 | +/// <https://github.com/RandyMcMillan/mempool_space.git> |
| 64 | +
|
| 65 | +/// |
| 66 | +/// USAGE: |
| 67 | +/// - mempool-space \--difficulty_adjustment (flagged) |
| 68 | +/// - mempool-space_difficulty_adjustment (executable) |
| 69 | +/// 1. Flags follow the mempool.space api/rest (replace dashes with underscores) |
| 70 | +/// 2. Flags invoke the executable |
| 71 | +
|
| 72 | +/// mempool-space \--option_str |
| 73 | +/// |
| 74 | +/// mempool-space \--blocks_tip_height |
| 75 | +/// |
| 76 | +/// mempool-space \--blocks_tip_hash |
| 77 | +/// |
| 78 | +/// mempool-space \--option_str arg |
| 79 | +/// |
| 80 | +/// mempool-space \--block 00000000000000000002d5c6e3451f94af29a3606e42b3c8f1db3cdfdc2bc934 |
| 81 | +/// |
| 82 | +/// mempool-space \--block $(mempool-space \--blocks_tip_hash) |
| 83 | +/// |
| 84 | +/// mempool-space_block $(mempool-space_blocks_tip_hash) |
| 85 | +/// |
| 86 | +
|
29 | 87 | /// `pub fn blocking(api: &String) -> Result<&str>`
|
30 | 88 | pub fn blocking(api: &String) -> Result<&str> {
|
31 | 89 | //print!("api={}", api);
|
|
0 commit comments