Skip to content

Commit

Permalink
Remove rust.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
notmandatory committed Mar 18, 2021
1 parent f549f5c commit 6662c8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 6 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,11 +40,8 @@ fn prepare_home_dir(data_dir: &str) -> PathBuf {
dir
}

fn client() -> Result<Client, Error> {
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<Client, Error> {
let url = match network {
bdk::bitcoin::Network::Bitcoin => { "ssl://electrum.blockstream.info:50002" }
bdk::bitcoin::Network::Testnet => { "ssl://electrum.blockstream.info:60002"}
_ => { "" }
Expand All @@ -72,8 +66,8 @@ fn check_address(client: &Client, addr: &str, from_height: Option<usize>) -> Res
Ok(array)
}

fn html(address: &str) -> Result<String, std::io::Error> {
let client = client().unwrap();
fn html(network: &Network, address: &str) -> Result<String, std::io::Error> {
let client = client(network).unwrap();
let list = check_address(&client, &address, Option::from(0)).unwrap();

let status = match list.last() {
Expand Down Expand Up @@ -185,7 +179,7 @@ fn main() {
let height = query.next().unwrap();
let h: usize = height.parse::<usize>().unwrap();

let client = client().unwrap();
let client = client(&network).unwrap();
let list = check_address(&client, &addr, Option::from(h));
return match list {
Ok(list) => {
Expand All @@ -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())?)
},
Expand Down

0 comments on commit 6662c8c

Please sign in to comment.