From 6662c8c7659367023ed197050c4297cc7dd88bec Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Wed, 17 Mar 2021 21:57:03 -0700 Subject: [PATCH] Remove rust.ini --- Cargo.toml | 1 - src/main.rs | 18 ++++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c212129..755ca9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ log = "0.4.0" env_logger = "0.8.2" serde_json = { version = "^1.0" } dirs-next = "2.0.0" -rust-ini = "0.16" structopt = "^0.3" [features] diff --git a/src/main.rs b/src/main.rs index d33c032..34732f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,12 +5,9 @@ extern crate simple_server; extern crate bdk; extern crate serde_json; extern crate bdk_macros; -extern crate ini; mod config; -use ini::Ini; - use std::fs; use std::path::PathBuf; use std::str::FromStr; @@ -43,11 +40,8 @@ fn prepare_home_dir(data_dir: &str) -> PathBuf { dir } -fn client() -> Result { - let conf = Ini::load_from_file("config.ini").unwrap(); - let section_bdk = conf.section(Some("BDK")).unwrap(); - let network = section_bdk.get("network").unwrap(); - let url = match network.parse().unwrap() { +fn client(network: &Network) -> Result { + let url = match network { bdk::bitcoin::Network::Bitcoin => { "ssl://electrum.blockstream.info:50002" } bdk::bitcoin::Network::Testnet => { "ssl://electrum.blockstream.info:60002"} _ => { "" } @@ -72,8 +66,8 @@ fn check_address(client: &Client, addr: &str, from_height: Option) -> Res Ok(array) } -fn html(address: &str) -> Result { - let client = client().unwrap(); +fn html(network: &Network, address: &str) -> Result { + let client = client(network).unwrap(); let list = check_address(&client, &address, Option::from(0)).unwrap(); let status = match list.last() { @@ -185,7 +179,7 @@ fn main() { let height = query.next().unwrap(); let h: usize = height.parse::().unwrap(); - let client = client().unwrap(); + let client = client(&network).unwrap(); let list = check_address(&client, &addr, Option::from(h)); return match list { Ok(list) => { @@ -205,7 +199,7 @@ fn main() { } (&Method::GET, "/bitcoin/") => { let address = request.uri().query().unwrap(); - return match html(address) { + return match html(&network, address) { Ok(txt) => { Ok(response.body(txt.as_bytes().to_vec())?) },