From f37b38eac71e7afed39251d76686ff42d1a5d4b2 Mon Sep 17 00:00:00 2001 From: pycanis Date: Mon, 23 Sep 2024 09:35:24 +0200 Subject: [PATCH] Remove questionable code --- src/config.rs | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/config.rs b/src/config.rs index acafb1d..7db603b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,7 @@ use crate::job::Job; use log::error; use serde::Deserialize; -use std::{env, fs, path::Path, process}; +use std::{fs, process}; const DEFAULT_CONFIG_PATH: &str = "config.yaml"; @@ -35,21 +35,6 @@ impl ValidConfig { pub async fn new(file_path: Option<&str>) -> Self { let path = file_path.unwrap_or(DEFAULT_CONFIG_PATH); - if !Path::new(path).exists() { - let default_config = r#"macaroon_path: "~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon" -cert_path: "~/.lnd/tls.cert" -server_url: "https://localhost:10009" -jobs: -# - name: "My first job" -# schedule: "0 30 9,12,15 1,15 May-Aug Mon,Wed,Fri 2018/2" -# amount_sats: 10000 -# ln_address_or_lnurl: "nick@domain.com" -# max_fee_sats: 5 -# memo: "Scheduled payment coming your way!""#; - - fs::write(path, default_config).expect("Failed to create default config"); - } - let config_raw_result = fs::read_to_string(path); let config_data = match config_raw_result { @@ -81,18 +66,17 @@ jobs: Some(jobs) => jobs.iter().map(|job| Job::new(job.to_owned())).collect(), }; - let home_dir = env::var("HOME").unwrap_or("~".to_string()); - - let cert_path = config.cert_path.replacen("~", &home_dir, 1); - let macaroon_path = config.macaroon_path.replacen("~", &home_dir, 1); - - tonic_lnd::connect(config.server_url.to_owned(), &cert_path, &macaroon_path) - .await - .expect("Failed to verify connection to LND node."); + tonic_lnd::connect( + config.server_url.to_owned(), + &config.cert_path, + &config.macaroon_path, + ) + .await + .expect("Failed to verify connection to LND node."); Self { - cert_path, - macaroon_path, + cert_path: config.cert_path, + macaroon_path: config.macaroon_path, server_url: config.server_url, jobs, }