Skip to content

Commit f8782d6

Browse files
committed
src/lib.rs:move fn api: add some docs
1 parent 33590f6 commit f8782d6

File tree

2 files changed

+75
-49
lines changed

2 files changed

+75
-49
lines changed

src/args.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,9 @@ use std::io::IsTerminal;
44
use std::path::PathBuf;
55
use std::process;
66

7+
use crate::api;
78
use crate::blocking;
89

9-
/// mempool-space --option_str sub_string
10-
///
11-
/// mempool-space_option_str sub_string
12-
///
13-
pub fn api(option: &str, sub_string: &str) -> String {
14-
use std::process::Command;
15-
16-
//if sub_string == "v1" {
17-
// print!("TODO: support --version v1 api versioning.");
18-
//} else if sub_string == "v2" {
19-
// print!("TODO: support --version v2 api versioning.");
20-
//} else {
21-
let output = if cfg!(target_os = "windows") {
22-
Command::new(format!("mempool-space_{}", option))
23-
.args(["/C", sub_string])
24-
.output()
25-
.expect("failed to execute process")
26-
} else {
27-
Command::new(format!("mempool-space_{}", option))
28-
.arg(sub_string)
29-
//.arg("echo hello")
30-
.output()
31-
.expect("failed to execute process")
32-
};
33-
34-
let result = String::from_utf8(output.stdout)
35-
.map_err(|non_utf8| String::from_utf8_lossy(non_utf8.as_bytes()).into_owned())
36-
.unwrap();
37-
print!("{}", result);
38-
result
39-
//}
40-
}
41-
4210
/// GET /api/v1/historical-price?currency=CURRENCY&timestamp=TIMESTAMP
4311
///
4412
/// <https://mempool.space/docs/api/rest#get-historical-price>

src/lib.rs

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,83 @@
77
// Author: Simon Brummer ([email protected])
88

99
#![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-
2310
use std::io::Read;
24-
25-
//const API_VERSION: &str = "v1";
26-
//
11+
const API_VERSION: &str = "v1";
2712
const URL: &str = "https://mempool.space/api";
2813

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+
2987
/// `pub fn blocking(api: &String) -> Result<&str>`
3088
pub fn blocking(api: &String) -> Result<&str> {
3189
//print!("api={}", api);

0 commit comments

Comments
 (0)