Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
improve: enable/disable config
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jul 18, 2023
1 parent 5611494 commit 741db2b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ email = "[email protected]"
[ln]
cln_path = "~/.lightning/signet/lightning-rpc"
authorized_users = ["04918dfc36c93e7db6cc0d60f37e1522f1c36b64d3f4b424c532d7c595febbc5"]
enable_node_manager = false
jwt_secret = "supersecretprivatekey"
ln_backend = "Cln"
fee_percent = 1.0
Expand Down
1 change: 1 addition & 0 deletions mint/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<XOnlyPublicKey>,
pub jwt_secret: String,
pub cln_path: Option<PathBuf>,
Expand Down
2 changes: 1 addition & 1 deletion mint/src/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub mod node_manager;
#[derive(Clone)]
pub struct Ln {
pub ln_processor: Arc<dyn LnProcessor>,
pub node_manager: node_manager::Nodemanger,
pub node_manager: Option<node_manager::Nodemanger>,
}

/// Possible states of an invoice
Expand Down
50 changes: 36 additions & 14 deletions mint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
};
Expand All @@ -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,
Expand Down

0 comments on commit 741db2b

Please sign in to comment.