lnd.rs 1.3 KB

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