Skip to main content

cdk_mintd/env_vars/
cln.rs

1//! CLN environment variables
2
3use std::env;
4use std::path::PathBuf;
5
6use crate::config::Cln;
7
8// CLN environment variables
9pub const ENV_CLN_RPC_PATH: &str = "CDK_MINTD_CLN_RPC_PATH";
10pub const ENV_CLN_BOLT12: &str = "CDK_MINTD_CLN_BOLT12";
11pub const ENV_CLN_FEE_PERCENT: &str = "CDK_MINTD_CLN_FEE_PERCENT";
12pub const ENV_CLN_RESERVE_FEE_MIN: &str = "CDK_MINTD_CLN_RESERVE_FEE_MIN";
13pub const ENV_CLN_EXPOSE_PRIVATE_CHANNELS: &str = "CDK_MINTD_CLN_EXPOSE_PRIVATE_CHANNELS";
14
15impl Cln {
16    pub fn from_env(mut self) -> Self {
17        // RPC Path
18        if let Ok(path) = env::var(ENV_CLN_RPC_PATH) {
19            self.rpc_path = PathBuf::from(path);
20        }
21
22        // BOLT12 flag
23        if let Ok(bolt12_str) = env::var(ENV_CLN_BOLT12) {
24            if let Ok(bolt12) = bolt12_str.parse() {
25                self.bolt12 = bolt12;
26            }
27        }
28
29        // Expose private channels
30        if let Ok(expose_str) = env::var(ENV_CLN_EXPOSE_PRIVATE_CHANNELS) {
31            if let Ok(expose) = expose_str.parse() {
32                self.expose_private_channels = expose;
33            }
34        }
35
36        // Fee percent
37        if let Ok(fee_str) = env::var(ENV_CLN_FEE_PERCENT) {
38            if let Ok(fee) = fee_str.parse() {
39                self.fee_percent = fee;
40            }
41        }
42
43        // Reserve fee minimum
44        if let Ok(reserve_fee_str) = env::var(ENV_CLN_RESERVE_FEE_MIN) {
45            if let Ok(reserve_fee) = reserve_fee_str.parse::<u64>() {
46                self.reserve_fee_min = reserve_fee.into();
47            }
48        }
49
50        self
51    }
52}