Skip to content

Commit

Permalink
let call = format!({}/{}, URL[rand::thread_rng().gen_range(0..2)], api);
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyMcMillan committed Oct 25, 2024
1 parent 25ae0fb commit fc6e4a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.0.57"
version = "0.0.58"
edition = "2021"
authors = ["RandyMcMillan <randy.lee.mcmillan@gmail.com>"]
description = "mempool.space api interface."
Expand Down Expand Up @@ -71,6 +71,7 @@ multipart = { version = "0.18.0", default-features = false, features = [
"client",
] }
pretty_assertions = "1.4.0"
rand = "0.8.5"
ratatui = { version = "0.28.0", features = ["serde", "macros", "all-widgets"] }
ratatui-splash-screen = "0.1.3"
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls-tls-webpki-roots"] }
Expand Down
17 changes: 14 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
use rand::Rng;
/// mempool.space api
///
/// <https://mempool.space/api>
///
/// <https://bitcoin.gob.sv/api>
///
// pull requests welcome
// add your clear net mempool.space instance here.
pub const URL: &[&str] = &[
"https://mempool.space/api",
"https://mempool.sweetsats.io/api",
"https://bitcoin.gob.sv/api",
"https://mempool.sweetsats.io/api",
"http:://localhost", //TODO support local instance
];

#[allow(dead_code)]
/// mempool.space onion api
/// <http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/api>
// pull requests welcome
// add your tor net mempool.space instance here.
pub const TOR_URL: &[&str] = &["http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/api"];

/// const API_VERSION: &str = "v1";
Expand Down Expand Up @@ -84,10 +94,11 @@ pub fn blocking(api: &String) -> Result<&str, ascii::AsciiChar> {
if api.contains("address") {
//print!("api={:?}", api);
}
let call = format!("{}/{}", URL[0], api);
let call = format!("{}/{}", URL[rand::thread_rng().gen_range(0..2)], api);
//println!("{}", call.clone());
let mut body = ureq::get(&call)
.call()
.expect("blocking(api: &String) GET {URL[0]}/{api} OR GET {URL[0]}/v1/{api}")
.expect("blocking(api: &String) GET {URL[0..2]}/{api} OR GET {URL[0..2]}/v1/{api}")
.into_reader();
let mut buf = Vec::new();
body.read_to_end(&mut buf).unwrap();
Expand Down

0 comments on commit fc6e4a1

Please sign in to comment.