cdk_mintd/env_vars/
lnd.rs

1//! LND environment variables
2
3use std::env;
4use std::path::PathBuf;
5
6use crate::config::Lnd;
7
8// LND environment variables
9pub const ENV_LND_ADDRESS: &str = "CDK_MINTD_LND_ADDRESS";
10pub const ENV_LND_CERT_FILE: &str = "CDK_MINTD_LND_CERT_FILE";
11pub const ENV_LND_MACAROON_FILE: &str = "CDK_MINTD_LND_MACAROON_FILE";
12pub const ENV_LND_FEE_PERCENT: &str = "CDK_MINTD_LND_FEE_PERCENT";
13pub const ENV_LND_RESERVE_FEE_MIN: &str = "CDK_MINTD_LND_RESERVE_FEE_MIN";
14
15impl Lnd {
16    pub fn from_env(mut self) -> Self {
17        if let Ok(address) = env::var(ENV_LND_ADDRESS) {
18            self.address = address;
19        }
20
21        if let Ok(cert_path) = env::var(ENV_LND_CERT_FILE) {
22            self.cert_file = PathBuf::from(cert_path);
23        }
24
25        if let Ok(macaroon_path) = env::var(ENV_LND_MACAROON_FILE) {
26            self.macaroon_file = PathBuf::from(macaroon_path);
27        }
28
29        if let Ok(fee_str) = env::var(ENV_LND_FEE_PERCENT) {
30            if let Ok(fee) = fee_str.parse() {
31                self.fee_percent = fee;
32            }
33        }
34
35        if let Ok(reserve_fee_str) = env::var(ENV_LND_RESERVE_FEE_MIN) {
36            if let Ok(reserve_fee) = reserve_fee_str.parse::<u64>() {
37                self.reserve_fee_min = reserve_fee.into();
38            }
39        }
40
41        self
42    }
43}