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