Skip to content

Commit

Permalink
Remove questionable code
Browse files Browse the repository at this point in the history
  • Loading branch information
pycanis committed Sep 23, 2024
1 parent c4e908a commit f37b38e
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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: "[email protected]"
# 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 {
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit f37b38e

Please sign in to comment.