Skip to content

Commit

Permalink
mempool-space --dashboard
Browse files Browse the repository at this point in the history
intermediate commit
  • Loading branch information
RandyMcMillan committed Sep 2, 2024
1 parent 070f643 commit d7108a1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
34 changes: 31 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,36 @@ pub const TOR_URL: &str = "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhh
///
/// pub fn api(option: &str, sub_string: &str) -> String
pub fn api(option: &str, sub_string: &str) -> String {
use std::process::Command;
if option.ends_with("dashboard") {
print!("api:invoke dashboard {:}", option);
let _ = if cfg!(target_os = "windows") {
std::process::Command::new(format!("mempool-space_{}", option))
//.args(["/C", sub_string])
.spawn()
.expect("failed to execute process")
} else {
std::process::Command::new(format!("mempool-space_{}", option))
//.arg(sub_string)
.spawn()
.expect("failed to execute process")
};
//let result = String::from_utf8(output.stdout)
// .map_err(|non_utf8| String::from_utf8_lossy(non_utf8.as_bytes()).into_owned())
// .unwrap();

//return result;
loop {}

//std::process::exit(0);
}

let output = if cfg!(target_os = "windows") {
Command::new(format!("mempool-space_{}", option))
std::process::Command::new(format!("mempool-space_{}", option))
.args(["/C", sub_string])
.output()
.expect("failed to execute process")
} else {
Command::new(format!("mempool-space_{}", option))
std::process::Command::new(format!("mempool-space_{}", option))
.arg(sub_string)
.output()
.expect("failed to execute process")
Expand All @@ -31,6 +52,10 @@ pub fn api(option: &str, sub_string: &str) -> String {
/// pub fn blocking(api: &String) -> Result<&str, ascii::AsciiChar>
/// prints to terminal
pub fn blocking(api: &String) -> Result<&str, ascii::AsciiChar> {
if api.ends_with("dashboard") {
print!("blocking:invoke dashboard {:?}", api);
std::process::exit(0);
}
let call = format!("{}/{}", URL, api);
let mut body = ureq::get(&call)
.call()
Expand All @@ -46,6 +71,9 @@ pub fn blocking(api: &String) -> Result<&str, ascii::AsciiChar> {
};
print!("{}", text);
} else {
if api.ends_with("dashboard") {
print!("invoke dashboard {:?}", &buf);
}
if api.ends_with("raw") {
//print!("api.ends_with raw");
print!("{:?}", &buf);
Expand Down
27 changes: 23 additions & 4 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ pub fn mining_pool_blocks(slug: &str, blockheight: &str) {
///
/// - Flags invoke the installed executable
///
/// DASHBOARD TUI INTERFACE (WIP)
///
/// ``mempool-space --dashboard (flagged)``
///
/// ``mempool-space_dashboard (executable)``
///
///
/// <https://mempool.space/docs/api/rest>
/// - [API/REST](https://mempool.space/docs/api/rest)
Expand Down Expand Up @@ -268,6 +274,9 @@ pub fn mining_pool_blocks(slug: &str, blockheight: &str) {
pub struct Args {
/// `mempool-space --version`
pub version: Option<String>,
/// `mempool-space --dashboard`
/// invoke the tui (WIP)
pub dashboard: Option<String>,
/// `https://mempool.space/api/v1/difficulty-adjustment`
pub difficulty_adjustment: Option<String>,
/// `https://mempool.space/api/v1/prices`
Expand Down Expand Up @@ -404,7 +413,10 @@ impl Args {
opts.optflag("o", "oneshot", "generates one shot links");
opts.optflag("p", "pretty", "prettifies the output");

//mempool api intercepts
// mempool-space_dashboard
opts.optflag("", "dashboard", "invoke the tui (WIP)");

// mempool api intercepts
// VERSION
// premeptive support v1,v2 etc...
// opts.optopt("", "version", "api call version path (v1/...)", "VERSION");
Expand Down Expand Up @@ -461,8 +473,7 @@ impl Args {
opts.optopt("", "min_height", "block txids api call", "MIN_HEIGHT");
opts.optopt("", "max_height", "block txids api call", "MAX_HEIGHT");

//MINING
//
// MINING
opts.optflag("", "mining_pools", "mining_pools api call");
opts.optopt("", "timeperiod", "mining_pools api call", "TIMEPERIOD");

Expand Down Expand Up @@ -491,7 +502,7 @@ impl Args {
opts.optflag("", "block_audit_summary", "block_audit_summary api call");
opts.optopt("", "blockhash", "block_audit_summary api call", "BLOCKHASH");

//OPTOPT
// OPTOPT
opts.optopt("c", "config", "sets the configuration file", "CONFIG");
opts.optopt("s", "server", "sets the address of the rustypaste server", "SERVER");
opts.optopt("a", "auth", "sets the authentication or delete token", "TOKEN");
Expand All @@ -509,6 +520,11 @@ impl Args {
}
};

//invoke the dashboard
// DASHBOARD
if matches.opt_present("dashboard") {
api("dashboard", &"");
};
//mempool api intercepts
// VERSION
// GENERAL
Expand Down Expand Up @@ -721,6 +737,9 @@ impl Args {
.or_else(|| matches.opt_str("c"))
.map(PathBuf::from),

// invoke mempool-space_dashboard
dashboard: matches.opt_str("dashboard"),

// mempool api intercepts
// mempool api version
version: matches.opt_str("version"),
Expand Down

0 comments on commit d7108a1

Please sign in to comment.