diff --git a/config.toml b/config.toml index ad2ef49..1470284 100644 --- a/config.toml +++ b/config.toml @@ -16,6 +16,7 @@ email = "me@example.com" [ln] cln_path = "~/.lightning/signet/lightning-rpc" authorized_users = ["04918dfc36c93e7db6cc0d60f37e1522f1c36b64d3f4b424c532d7c595febbc5"] +enable_node_manager = false jwt_secret = "supersecretprivatekey" ln_backend = "Cln" fee_percent = 1.0 diff --git a/mint/src/config.rs b/mint/src/config.rs index 0747e78..8bb3188 100644 --- a/mint/src/config.rs +++ b/mint/src/config.rs @@ -87,6 +87,7 @@ pub enum LnBackend { #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct Ln { pub ln_backend: LnBackend, + pub enable_node_manager: bool, pub authorized_users: HashSet, pub jwt_secret: String, pub cln_path: Option, diff --git a/mint/src/ln/mod.rs b/mint/src/ln/mod.rs index 4f90da6..576bc8f 100644 --- a/mint/src/ln/mod.rs +++ b/mint/src/ln/mod.rs @@ -21,7 +21,7 @@ pub mod node_manager; #[derive(Clone)] pub struct Ln { pub ln_processor: Arc, - pub node_manager: node_manager::Nodemanger, + pub node_manager: Option, } /// Possible states of an invoice diff --git a/mint/src/main.rs b/mint/src/main.rs index 12e16cc..6afa373 100644 --- a/mint/src/main.rs +++ b/mint/src/main.rs @@ -111,23 +111,41 @@ async fn main() -> anyhow::Result<()> { .ok_or(anyhow!("cln socket not defined"))?; let cln = Arc::new(Cln::new(cln_socket, db.clone(), mint.clone()).await?); + + let node_manager = match settings.ln.enable_node_manager { + true => Some(ln::node_manager::Nodemanger::Cln(cln.clone())), + false => None, + }; + Ln { ln_processor: cln.clone(), - node_manager: ln::node_manager::Nodemanger::Cln(cln), + node_manager, } } LnBackend::Greenlight => { let gln = Arc::new(Greenlight::new(db.clone(), mint.clone()).await?); + + let node_manager = match settings.ln.enable_node_manager { + true => Some(ln::node_manager::Nodemanger::Greenlight(gln.clone())), + false => None, + }; + Ln { ln_processor: gln.clone(), - node_manager: ln::node_manager::Nodemanger::Greenlight(gln), + node_manager, } } LnBackend::Ldk => { let ldk = Arc::new(Ldk::new(&settings, db.clone()).await?); + + let node_manager = match settings.ln.enable_node_manager { + true => Some(ln::node_manager::Nodemanger::Ldk(ldk.clone())), + false => None, + }; + Ln { ln_processor: ldk.clone(), - node_manager: ln::node_manager::Nodemanger::Ldk(ldk), + node_manager, } } }; @@ -147,18 +165,22 @@ async fn main() -> anyhow::Result<()> { let settings_clone = settings.clone(); let db_clone = db.clone(); - tokio::spawn(async move { - loop { - if let Err(err) = ln_clone - .node_manager - .start_server(&settings_clone, db_clone.clone()) - .await - { - warn!("{:?}", err) - } - } - }); + if settings.ln.enable_node_manager { + tokio::spawn(async move { + loop { + if let Err(err) = ln_clone + .clone() + .node_manager + .unwrap() + .start_server(&settings_clone, db_clone.clone()) + .await + { + warn!("{:?}", err) + } + } + }); + } let state = MintState { db, ln,