1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
use std::path::Path;
use url::Url;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Config {
pub base_url: Url,
pub db_url: String,
pub port: u16,
pub payto: Url,
pub confirmation: u8,
pub btc_wallet: String,
pub btc_chain: String,
}
impl Config {
pub fn from_path(path: impl AsRef<Path>) -> Self {
let conf = ini::Ini::load_from_file(path).unwrap();
let ex_conf = conf.section(Some("exchange")).unwrap();
let self_conf = conf.section(Some("depolymerizer-bitcoin")).unwrap();
Self {
base_url: Url::parse(ex_conf.get("BASE_URL").expect("Missing config BASE_URL"))
.expect("BASE_URL is not a valid url"),
db_url: self_conf
.get("DB_URL")
.expect("Missing config DB_URL")
.to_string(),
port: self_conf
.get("PORT")
.unwrap_or("8080")
.parse()
.expect("Config PORT is not a number"),
payto: Url::parse(self_conf.get("PAYTO").unwrap()).unwrap(),
confirmation: self_conf
.get("CONFIRMATION")
.unwrap_or("1")
.parse()
.expect("Config CONFIRMATION is not a number"),
btc_wallet: self_conf.get("BTC_WALLET").unwrap_or("wire").to_string(),
btc_chain: self_conf.get("BTC_CHAIN").unwrap_or("regtest").to_string(),
}
}
}
|