-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
10 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
|
@@ -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 { | ||
|
@@ -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, | ||
} | ||
|