mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-18 21:25:09 +01:00
feat: remove unused ln_routers (#1059)
* feat: remove unused ln_routers * feat: allow other routers to be nested
This commit is contained in:
@@ -101,8 +101,15 @@ async fn start_fake_auth_mint(
|
||||
println!("Fake auth mint shutdown signal received");
|
||||
};
|
||||
|
||||
match cdk_mintd::run_mintd_with_shutdown(&temp_dir, &settings, shutdown_future, None, None)
|
||||
.await
|
||||
match cdk_mintd::run_mintd_with_shutdown(
|
||||
&temp_dir,
|
||||
&settings,
|
||||
shutdown_future,
|
||||
None,
|
||||
None,
|
||||
vec![],
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => println!("Fake auth mint exited normally"),
|
||||
Err(e) => eprintln!("Fake auth mint exited with error: {e}"),
|
||||
|
||||
@@ -100,8 +100,15 @@ async fn start_fake_mint(
|
||||
println!("Fake mint shutdown signal received");
|
||||
};
|
||||
|
||||
match cdk_mintd::run_mintd_with_shutdown(&temp_dir, &settings, shutdown_future, None, None)
|
||||
.await
|
||||
match cdk_mintd::run_mintd_with_shutdown(
|
||||
&temp_dir,
|
||||
&settings,
|
||||
shutdown_future,
|
||||
None,
|
||||
None,
|
||||
vec![],
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => println!("Fake mint exited normally"),
|
||||
Err(e) => eprintln!("Fake mint exited with error: {e}"),
|
||||
|
||||
@@ -107,8 +107,15 @@ async fn start_cln_mint(
|
||||
println!("CLN mint shutdown signal received");
|
||||
};
|
||||
|
||||
match cdk_mintd::run_mintd_with_shutdown(&temp_dir, &settings, shutdown_future, None, None)
|
||||
.await
|
||||
match cdk_mintd::run_mintd_with_shutdown(
|
||||
&temp_dir,
|
||||
&settings,
|
||||
shutdown_future,
|
||||
None,
|
||||
None,
|
||||
vec![],
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => println!("CLN mint exited normally"),
|
||||
Err(e) => eprintln!("CLN mint exited with error: {e}"),
|
||||
@@ -172,6 +179,7 @@ async fn start_lnd_mint(
|
||||
shutdown_future,
|
||||
None,
|
||||
None,
|
||||
vec![],
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -238,6 +246,7 @@ async fn start_ldk_mint(
|
||||
shutdown_future,
|
||||
None,
|
||||
runtime,
|
||||
vec![],
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -337,27 +337,18 @@ async fn configure_mint_builder(
|
||||
runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
work_dir: &Path,
|
||||
kv_store: Option<Arc<dyn MintKVStore<Err = cdk::cdk_database::Error> + Send + Sync>>,
|
||||
) -> Result<(MintBuilder, Vec<Router>)> {
|
||||
let mut ln_routers = vec![];
|
||||
|
||||
) -> Result<MintBuilder> {
|
||||
// Configure basic mint information
|
||||
let mint_builder = configure_basic_info(settings, mint_builder);
|
||||
|
||||
// Configure lightning backend
|
||||
let mint_builder = configure_lightning_backend(
|
||||
settings,
|
||||
mint_builder,
|
||||
&mut ln_routers,
|
||||
runtime,
|
||||
work_dir,
|
||||
kv_store,
|
||||
)
|
||||
.await?;
|
||||
let mint_builder =
|
||||
configure_lightning_backend(settings, mint_builder, runtime, work_dir, kv_store).await?;
|
||||
|
||||
// Configure caching
|
||||
let mint_builder = configure_cache(settings, mint_builder);
|
||||
|
||||
Ok((mint_builder, ln_routers))
|
||||
Ok(mint_builder)
|
||||
}
|
||||
|
||||
/// Configures basic mint information (name, contact info, descriptions, etc.)
|
||||
@@ -414,7 +405,6 @@ fn configure_basic_info(settings: &config::Settings, mint_builder: MintBuilder)
|
||||
async fn configure_lightning_backend(
|
||||
settings: &config::Settings,
|
||||
mut mint_builder: MintBuilder,
|
||||
ln_routers: &mut Vec<Router>,
|
||||
_runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
work_dir: &Path,
|
||||
_kv_store: Option<Arc<dyn MintKVStore<Err = cdk::cdk_database::Error> + Send + Sync>>,
|
||||
@@ -436,14 +426,7 @@ async fn configure_lightning_backend(
|
||||
.clone()
|
||||
.expect("Config checked at load that cln is some");
|
||||
let cln = cln_settings
|
||||
.setup(
|
||||
ln_routers,
|
||||
settings,
|
||||
CurrencyUnit::Msat,
|
||||
None,
|
||||
work_dir,
|
||||
None,
|
||||
)
|
||||
.setup(settings, CurrencyUnit::Msat, None, work_dir, None)
|
||||
.await?;
|
||||
#[cfg(feature = "prometheus")]
|
||||
let cln = MetricsMintPayment::new(cln);
|
||||
@@ -461,14 +444,7 @@ async fn configure_lightning_backend(
|
||||
LnBackend::LNbits => {
|
||||
let lnbits_settings = settings.clone().lnbits.expect("Checked on config load");
|
||||
let lnbits = lnbits_settings
|
||||
.setup(
|
||||
ln_routers,
|
||||
settings,
|
||||
CurrencyUnit::Sat,
|
||||
None,
|
||||
work_dir,
|
||||
None,
|
||||
)
|
||||
.setup(settings, CurrencyUnit::Sat, None, work_dir, None)
|
||||
.await?;
|
||||
#[cfg(feature = "prometheus")]
|
||||
let lnbits = MetricsMintPayment::new(lnbits);
|
||||
@@ -486,14 +462,7 @@ async fn configure_lightning_backend(
|
||||
LnBackend::Lnd => {
|
||||
let lnd_settings = settings.clone().lnd.expect("Checked at config load");
|
||||
let lnd = lnd_settings
|
||||
.setup(
|
||||
ln_routers,
|
||||
settings,
|
||||
CurrencyUnit::Msat,
|
||||
None,
|
||||
work_dir,
|
||||
None,
|
||||
)
|
||||
.setup(settings, CurrencyUnit::Msat, None, work_dir, None)
|
||||
.await?;
|
||||
#[cfg(feature = "prometheus")]
|
||||
let lnd = MetricsMintPayment::new(lnd);
|
||||
@@ -514,14 +483,7 @@ async fn configure_lightning_backend(
|
||||
|
||||
for unit in fake_wallet.clone().supported_units {
|
||||
let fake = fake_wallet
|
||||
.setup(
|
||||
ln_routers,
|
||||
settings,
|
||||
unit.clone(),
|
||||
None,
|
||||
work_dir,
|
||||
_kv_store.clone(),
|
||||
)
|
||||
.setup(settings, unit.clone(), None, work_dir, _kv_store.clone())
|
||||
.await?;
|
||||
#[cfg(feature = "prometheus")]
|
||||
let fake = MetricsMintPayment::new(fake);
|
||||
@@ -552,7 +514,7 @@ async fn configure_lightning_backend(
|
||||
for unit in grpc_processor.clone().supported_units {
|
||||
tracing::debug!("Adding unit: {:?}", unit);
|
||||
let processor = grpc_processor
|
||||
.setup(ln_routers, settings, unit.clone(), None, work_dir, None)
|
||||
.setup(settings, unit.clone(), None, work_dir, None)
|
||||
.await?;
|
||||
#[cfg(feature = "prometheus")]
|
||||
let processor = MetricsMintPayment::new(processor);
|
||||
@@ -573,14 +535,7 @@ async fn configure_lightning_backend(
|
||||
tracing::info!("Using LDK Node backend: {:?}", ldk_node_settings);
|
||||
|
||||
let ldk_node = ldk_node_settings
|
||||
.setup(
|
||||
ln_routers,
|
||||
settings,
|
||||
CurrencyUnit::Sat,
|
||||
_runtime,
|
||||
work_dir,
|
||||
None,
|
||||
)
|
||||
.setup(settings, CurrencyUnit::Sat, _runtime, work_dir, None)
|
||||
.await?;
|
||||
|
||||
mint_builder = configure_backend_for_unit(
|
||||
@@ -893,10 +848,10 @@ async fn build_mint(
|
||||
async fn start_services_with_shutdown(
|
||||
mint: Arc<cdk::mint::Mint>,
|
||||
settings: &config::Settings,
|
||||
ln_routers: Vec<Router>,
|
||||
work_dir: &Path,
|
||||
mint_builder_info: cdk::nuts::MintInfo,
|
||||
shutdown_signal: impl std::future::Future<Output = ()> + Send + 'static,
|
||||
routers: Vec<Router>,
|
||||
) -> Result<()> {
|
||||
let listen_addr = settings.info.listen_host.clone();
|
||||
let listen_port = settings.info.listen_port;
|
||||
@@ -980,6 +935,10 @@ async fn start_services_with_shutdown(
|
||||
)
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
for router in routers {
|
||||
mint_service = mint_service.merge(router);
|
||||
}
|
||||
|
||||
#[cfg(feature = "swagger")]
|
||||
{
|
||||
if settings.info.enable_swagger_ui.unwrap_or(false) {
|
||||
@@ -1031,9 +990,6 @@ async fn start_services_with_shutdown(
|
||||
|
||||
#[cfg(not(feature = "prometheus"))]
|
||||
let prometheus_handle: Option<tokio::task::JoinHandle<()>> = None;
|
||||
for router in ln_routers {
|
||||
mint_service = mint_service.merge(router);
|
||||
}
|
||||
|
||||
mint.start().await?;
|
||||
|
||||
@@ -1119,6 +1075,7 @@ pub async fn run_mintd(
|
||||
db_password: Option<String>,
|
||||
enable_logging: bool,
|
||||
runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
routers: Vec<Router>,
|
||||
) -> Result<()> {
|
||||
let _guard = if enable_logging {
|
||||
setup_tracing(work_dir, &settings.info.logging)?
|
||||
@@ -1126,8 +1083,15 @@ pub async fn run_mintd(
|
||||
None
|
||||
};
|
||||
|
||||
let result =
|
||||
run_mintd_with_shutdown(work_dir, settings, shutdown_signal(), db_password, runtime).await;
|
||||
let result = run_mintd_with_shutdown(
|
||||
work_dir,
|
||||
settings,
|
||||
shutdown_signal(),
|
||||
db_password,
|
||||
runtime,
|
||||
routers,
|
||||
)
|
||||
.await;
|
||||
|
||||
// Explicitly drop the guard to ensure proper cleanup
|
||||
if let Some(guard) = _guard {
|
||||
@@ -1149,12 +1113,13 @@ pub async fn run_mintd_with_shutdown(
|
||||
shutdown_signal: impl std::future::Future<Output = ()> + Send + 'static,
|
||||
db_password: Option<String>,
|
||||
runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
routers: Vec<Router>,
|
||||
) -> Result<()> {
|
||||
let (localstore, keystore, kv) = initial_setup(work_dir, settings, db_password.clone()).await?;
|
||||
|
||||
let mint_builder = MintBuilder::new(localstore);
|
||||
|
||||
let (mint_builder, ln_routers) =
|
||||
let mint_builder =
|
||||
configure_mint_builder(settings, mint_builder, runtime, work_dir, Some(kv)).await?;
|
||||
#[cfg(feature = "auth")]
|
||||
let mint_builder = setup_authentication(settings, work_dir, mint_builder, db_password).await?;
|
||||
@@ -1173,10 +1138,10 @@ pub async fn run_mintd_with_shutdown(
|
||||
let result = start_services_with_shutdown(
|
||||
mint.clone(),
|
||||
settings,
|
||||
ln_routers,
|
||||
work_dir,
|
||||
mint.mint_info().await?,
|
||||
shutdown_signal,
|
||||
routers,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ fn main() -> Result<()> {
|
||||
password,
|
||||
args.enable_logging,
|
||||
Some(rt_clone),
|
||||
vec![],
|
||||
)
|
||||
.await
|
||||
})
|
||||
|
||||
@@ -8,7 +8,6 @@ use std::sync::Arc;
|
||||
#[cfg(feature = "cln")]
|
||||
use anyhow::anyhow;
|
||||
use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
#[cfg(feature = "fakewallet")]
|
||||
use bip39::rand::{thread_rng, Rng};
|
||||
use cdk::cdk_database::MintKVStore;
|
||||
@@ -31,7 +30,6 @@ use crate::expand_path;
|
||||
pub trait LnBackendSetup {
|
||||
async fn setup(
|
||||
&self,
|
||||
routers: &mut Vec<Router>,
|
||||
settings: &Settings,
|
||||
unit: CurrencyUnit,
|
||||
runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
@@ -45,7 +43,6 @@ pub trait LnBackendSetup {
|
||||
impl LnBackendSetup for config::Cln {
|
||||
async fn setup(
|
||||
&self,
|
||||
_routers: &mut Vec<Router>,
|
||||
_settings: &Settings,
|
||||
_unit: CurrencyUnit,
|
||||
_runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
@@ -75,7 +72,6 @@ impl LnBackendSetup for config::Cln {
|
||||
impl LnBackendSetup for config::LNbits {
|
||||
async fn setup(
|
||||
&self,
|
||||
_routers: &mut Vec<Router>,
|
||||
_settings: &Settings,
|
||||
_unit: CurrencyUnit,
|
||||
_runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
@@ -110,7 +106,6 @@ impl LnBackendSetup for config::LNbits {
|
||||
impl LnBackendSetup for config::Lnd {
|
||||
async fn setup(
|
||||
&self,
|
||||
_routers: &mut Vec<Router>,
|
||||
_settings: &Settings,
|
||||
_unit: CurrencyUnit,
|
||||
_runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
@@ -143,7 +138,6 @@ impl LnBackendSetup for config::Lnd {
|
||||
impl LnBackendSetup for config::FakeWallet {
|
||||
async fn setup(
|
||||
&self,
|
||||
_router: &mut Vec<Router>,
|
||||
_settings: &Settings,
|
||||
unit: CurrencyUnit,
|
||||
_runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
@@ -176,7 +170,6 @@ impl LnBackendSetup for config::FakeWallet {
|
||||
impl LnBackendSetup for config::GrpcProcessor {
|
||||
async fn setup(
|
||||
&self,
|
||||
_routers: &mut Vec<Router>,
|
||||
_settings: &Settings,
|
||||
_unit: CurrencyUnit,
|
||||
_runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
@@ -199,7 +192,6 @@ impl LnBackendSetup for config::GrpcProcessor {
|
||||
impl LnBackendSetup for config::LdkNode {
|
||||
async fn setup(
|
||||
&self,
|
||||
_routers: &mut Vec<Router>,
|
||||
_settings: &Settings,
|
||||
_unit: CurrencyUnit,
|
||||
runtime: Option<std::sync::Arc<tokio::runtime::Runtime>>,
|
||||
|
||||
Reference in New Issue
Block a user