From e90dc6dbfdcaec393c10ad7ddae29244f8b1bfe3 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Sun, 17 Nov 2024 23:46:25 +0000 Subject: [PATCH] feat: bolt12 mint builder --- crates/cdk-cln/src/lib.rs | 13 +- crates/cdk-fake-wallet/src/lib.rs | 2 - .../src/init_fake_wallet.rs | 8 +- .../cdk-integration-tests/src/init_regtest.rs | 13 +- crates/cdk-integration-tests/src/lib.rs | 2 +- crates/cdk-lnbits/src/lib.rs | 2 - crates/cdk-lnd/src/lib.rs | 2 - crates/cdk-mintd/src/main.rs | 77 +++------ crates/cdk-mintd/src/setup.rs | 2 +- crates/cdk-phoenixd/src/lib.rs | 2 - crates/cdk-strike/src/lib.rs | 2 - crates/cdk/src/cdk_lightning/mod.rs | 4 - crates/cdk/src/mint/builder.rs | 152 ++++++++++-------- crates/cdk/src/mint/melt.rs | 38 ++--- crates/cdk/src/mint/mint_18.rs | 12 +- crates/cdk/src/mint/mint_nut04.rs | 12 +- crates/cdk/src/mint/mod.rs | 14 +- crates/cdk/src/types.rs | 1 + 18 files changed, 145 insertions(+), 213 deletions(-) diff --git a/crates/cdk-cln/src/lib.rs b/crates/cdk-cln/src/lib.rs index e1d6061e..dcd4aaea 100644 --- a/crates/cdk-cln/src/lib.rs +++ b/crates/cdk-cln/src/lib.rs @@ -45,8 +45,6 @@ pub struct Cln { rpc_socket: PathBuf, cln_client: Arc>, fee_reserve: FeeReserve, - bolt12_mint: bool, - bolt12_melt: bool, wait_invoice_cancel_token: CancellationToken, wait_invoice_is_active: Arc, bolt12_wait_invoice_is_active: Arc, @@ -54,20 +52,13 @@ pub struct Cln { impl Cln { /// Create new [`Cln`] - pub async fn new( - rpc_socket: PathBuf, - fee_reserve: FeeReserve, - bolt12_mint: bool, - bolt12_melt: bool, - ) -> Result { + pub async fn new(rpc_socket: PathBuf, fee_reserve: FeeReserve) -> Result { let cln_client = cln_rpc::ClnRpc::new(&rpc_socket).await?; Ok(Self { rpc_socket, cln_client: Arc::new(Mutex::new(cln_client)), fee_reserve, - bolt12_mint, - bolt12_melt, wait_invoice_cancel_token: CancellationToken::new(), wait_invoice_is_active: Arc::new(AtomicBool::new(false)), bolt12_wait_invoice_is_active: Arc::new(AtomicBool::new(false)), @@ -83,8 +74,6 @@ impl MintLightning for Cln { Settings { mpp: true, unit: CurrencyUnit::Msat, - bolt12_mint: self.bolt12_mint, - bolt12_melt: self.bolt12_melt, invoice_description: true, } } diff --git a/crates/cdk-fake-wallet/src/lib.rs b/crates/cdk-fake-wallet/src/lib.rs index 4223d04f..f226cc97 100644 --- a/crates/cdk-fake-wallet/src/lib.rs +++ b/crates/cdk-fake-wallet/src/lib.rs @@ -104,8 +104,6 @@ impl MintLightning for FakeWallet { Settings { mpp: true, unit: CurrencyUnit::Msat, - bolt12_mint: false, - bolt12_melt: false, invoice_description: true, } } diff --git a/crates/cdk-integration-tests/src/init_fake_wallet.rs b/crates/cdk-integration-tests/src/init_fake_wallet.rs index 40ef9d91..e6c47e7c 100644 --- a/crates/cdk-integration-tests/src/init_fake_wallet.rs +++ b/crates/cdk-integration-tests/src/init_fake_wallet.rs @@ -7,7 +7,6 @@ use cdk::cdk_database::{self, MintDatabase}; use cdk::cdk_lightning::MintLightning; use cdk::mint::FeeReserve; use cdk::nuts::CurrencyUnit; -use cdk::types::LnKey; use cdk_fake_wallet::FakeWallet; use tokio::sync::Notify; use tower_http::cors::CorsLayer; @@ -33,7 +32,7 @@ where tracing_subscriber::fmt().with_env_filter(env_filter).init(); let mut ln_backends: HashMap< - LnKey, + CurrencyUnit, Arc + Sync + Send>, > = HashMap::new(); @@ -44,10 +43,7 @@ where let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0); - ln_backends.insert( - LnKey::new(CurrencyUnit::Sat, cdk::nuts::PaymentMethod::Bolt11), - Arc::new(fake_wallet), - ); + ln_backends.insert(CurrencyUnit::Sat, Arc::new(fake_wallet)); let mint = create_mint(database, ln_backends.clone()).await?; let cache_ttl = 3600; diff --git a/crates/cdk-integration-tests/src/init_regtest.rs b/crates/cdk-integration-tests/src/init_regtest.rs index df8db224..9550b440 100644 --- a/crates/cdk-integration-tests/src/init_regtest.rs +++ b/crates/cdk-integration-tests/src/init_regtest.rs @@ -10,7 +10,7 @@ use cdk::cdk_database::{self, MintDatabase}; use cdk::cdk_lightning::MintLightning; use cdk::mint::{FeeReserve, Mint}; use cdk::nuts::{CurrencyUnit, MintInfo}; -use cdk::types::{LnKey, QuoteTTL}; +use cdk::types::QuoteTTL; use cdk_cln::Cln as CdkCln; use ln_regtest_rs::bitcoin_client::BitcoinClient; use ln_regtest_rs::bitcoind::Bitcoind; @@ -138,13 +138,13 @@ pub async fn create_cln_backend(cln_client: &ClnClient) -> Result { percent_fee_reserve: 1.0, }; - Ok(CdkCln::new(rpc_path, fee_reserve, true, true).await?) + Ok(CdkCln::new(rpc_path, fee_reserve).await?) } pub async fn create_mint( database: D, ln_backends: HashMap< - LnKey, + CurrencyUnit, Arc + Sync + Send>, >, ) -> Result @@ -207,14 +207,11 @@ where let cln_backend = create_cln_backend(&cln_client).await?; let mut ln_backends: HashMap< - LnKey, + CurrencyUnit, Arc + Sync + Send>, > = HashMap::new(); - ln_backends.insert( - LnKey::new(CurrencyUnit::Sat, cdk::nuts::PaymentMethod::Bolt11), - Arc::new(cln_backend), - ); + ln_backends.insert(CurrencyUnit::Sat, Arc::new(cln_backend)); let mint = create_mint(database, ln_backends.clone()).await?; let cache_time_to_live = 3600; diff --git a/crates/cdk-integration-tests/src/lib.rs b/crates/cdk-integration-tests/src/lib.rs index 604dd357..9b2882f5 100644 --- a/crates/cdk-integration-tests/src/lib.rs +++ b/crates/cdk-integration-tests/src/lib.rs @@ -52,7 +52,7 @@ pub fn create_backends_fake_wallet( pub async fn start_mint( ln_backends: HashMap< - LnKey, + CurrencyUnit, Arc + Sync + Send>, >, supported_units: HashMap, diff --git a/crates/cdk-lnbits/src/lib.rs b/crates/cdk-lnbits/src/lib.rs index f0af24c9..e1ea7d79 100644 --- a/crates/cdk-lnbits/src/lib.rs +++ b/crates/cdk-lnbits/src/lib.rs @@ -73,8 +73,6 @@ impl MintLightning for LNbits { Settings { mpp: false, unit: CurrencyUnit::Sat, - bolt12_mint: false, - bolt12_melt: false, invoice_description: true, } } diff --git a/crates/cdk-lnd/src/lib.rs b/crates/cdk-lnd/src/lib.rs index 129c7a4f..e76df7ec 100644 --- a/crates/cdk-lnd/src/lib.rs +++ b/crates/cdk-lnd/src/lib.rs @@ -81,8 +81,6 @@ impl MintLightning for Lnd { Settings { mpp: true, unit: CurrencyUnit::Msat, - bolt12_mint: false, - bolt12_melt: false, invoice_description: true, } } diff --git a/crates/cdk-mintd/src/main.rs b/crates/cdk-mintd/src/main.rs index 673ca859..ae827ed1 100644 --- a/crates/cdk-mintd/src/main.rs +++ b/crates/cdk-mintd/src/main.rs @@ -144,12 +144,8 @@ async fn main() -> anyhow::Result<()> { }; ln_backends.insert(ln_key, cln.clone()); - mint_builder = mint_builder.add_ln_backend( - CurrencyUnit::Sat, - PaymentMethod::Bolt11, - mint_melt_limits, - cln.clone(), - ); + mint_builder = + mint_builder.add_ln_backend(CurrencyUnit::Sat, mint_melt_limits, cln.clone()); if cln_settings.bolt12 { let ln_key = LnKey { @@ -158,12 +154,8 @@ async fn main() -> anyhow::Result<()> { }; ln_backends.insert(ln_key, cln.clone()); - mint_builder = mint_builder.add_ln_backend( - CurrencyUnit::Sat, - PaymentMethod::Bolt12, - mint_melt_limits, - cln, - ) + mint_builder = + mint_builder.add_bolt12_ln_backend(CurrencyUnit::Sat, mint_melt_limits, cln) } } LnBackend::Strike => { @@ -178,12 +170,8 @@ async fn main() -> anyhow::Result<()> { .setup(&mut ln_routers, &settings, unit.clone()) .await?; - mint_builder = mint_builder.add_ln_backend( - unit, - PaymentMethod::Bolt11, - mint_melt_limits, - Arc::new(strike), - ); + mint_builder = + mint_builder.add_ln_backend(unit, mint_melt_limits, Arc::new(strike)); } } LnBackend::LNbits => { @@ -192,12 +180,8 @@ async fn main() -> anyhow::Result<()> { .setup(&mut ln_routers, &settings, CurrencyUnit::Sat) .await?; - mint_builder = mint_builder.add_ln_backend( - CurrencyUnit::Sat, - PaymentMethod::Bolt11, - mint_melt_limits, - Arc::new(lnbits), - ); + mint_builder = + mint_builder.add_ln_backend(CurrencyUnit::Sat, mint_melt_limits, Arc::new(lnbits)); } LnBackend::Phoenixd => { let phd_settings = settings.clone().phoenixd.expect("Checked at config load"); @@ -205,12 +189,8 @@ async fn main() -> anyhow::Result<()> { .setup(&mut ln_routers, &settings, CurrencyUnit::Sat) .await?; - mint_builder = mint_builder.add_ln_backend( - CurrencyUnit::Sat, - PaymentMethod::Bolt11, - mint_melt_limits, - Arc::new(phd), - ); + mint_builder = + mint_builder.add_ln_backend(CurrencyUnit::Sat, mint_melt_limits, Arc::new(phd)); } LnBackend::Lnd => { let lnd_settings = settings.clone().lnd.expect("Checked at config load"); @@ -218,12 +198,8 @@ async fn main() -> anyhow::Result<()> { .setup(&mut ln_routers, &settings, CurrencyUnit::Msat) .await?; - mint_builder = mint_builder.add_ln_backend( - CurrencyUnit::Sat, - PaymentMethod::Bolt11, - mint_melt_limits, - Arc::new(lnd), - ); + mint_builder = + mint_builder.add_ln_backend(CurrencyUnit::Sat, mint_melt_limits, Arc::new(lnd)); } LnBackend::FakeWallet => { let fake_wallet = settings.clone().fake_wallet.expect("Fake wallet defined"); @@ -235,33 +211,16 @@ async fn main() -> anyhow::Result<()> { let fake = Arc::new(fake); - mint_builder = mint_builder.add_ln_backend( - unit.clone(), - PaymentMethod::Bolt11, - mint_melt_limits, - fake.clone(), - ); + mint_builder = + mint_builder.add_ln_backend(unit.clone(), mint_melt_limits, fake.clone()); - mint_builder = mint_builder.add_ln_backend( - unit, - PaymentMethod::Bolt12, - mint_melt_limits, - fake.clone(), - ); + // TODO: Bolt12 for fake + // mint_builder = + // mint_builder.add_bolt12_ln_backend(unit, mint_melt_limits, fake.clone()); } } }; - let support_bolt12_mint = ln_backends.iter().any(|(_k, ln)| { - let settings = ln.get_settings(); - settings.bolt12_mint - }); - - let support_bolt12_melt = ln_backends.iter().any(|(_k, ln)| { - let settings = ln.get_settings(); - settings.bolt12_melt - }); - if let Some(long_description) = &settings.mint_info.description_long { mint_builder = mint_builder.with_long_description(long_description.to_string()); } @@ -326,7 +285,7 @@ async fn main() -> anyhow::Result<()> { .seconds_to_extend_cache_by .unwrap_or(DEFAULT_CACHE_TTI_SECS); - let include_bolt12 = support_bolt12_mint || support_bolt12_melt; + let include_bolt12 = !mint.bolt12_backends.is_empty(); let v1_service = cdk_axum::create_mint_router(Arc::clone(&mint), cache_ttl, cache_tti, include_bolt12) diff --git a/crates/cdk-mintd/src/setup.rs b/crates/cdk-mintd/src/setup.rs index cfcc0294..9a2cc820 100644 --- a/crates/cdk-mintd/src/setup.rs +++ b/crates/cdk-mintd/src/setup.rs @@ -44,7 +44,7 @@ impl LnBackendSetup for config::Cln { percent_fee_reserve: self.fee_percent, }; - let cln = cdk_cln::Cln::new(cln_socket, fee_reserve, true, true).await?; + let cln = cdk_cln::Cln::new(cln_socket, fee_reserve).await?; Ok(cln) } diff --git a/crates/cdk-phoenixd/src/lib.rs b/crates/cdk-phoenixd/src/lib.rs index 1615a050..879f48c0 100644 --- a/crates/cdk-phoenixd/src/lib.rs +++ b/crates/cdk-phoenixd/src/lib.rs @@ -81,8 +81,6 @@ impl MintLightning for Phoenixd { Settings { mpp: false, unit: CurrencyUnit::Sat, - bolt12_mint: false, - bolt12_melt: true, invoice_description: true, } } diff --git a/crates/cdk-strike/src/lib.rs b/crates/cdk-strike/src/lib.rs index fff4998d..a5ba28c9 100644 --- a/crates/cdk-strike/src/lib.rs +++ b/crates/cdk-strike/src/lib.rs @@ -70,8 +70,6 @@ impl MintLightning for Strike { Settings { mpp: false, unit: self.unit.clone(), - bolt12_mint: false, - bolt12_melt: false, invoice_description: true, } } diff --git a/crates/cdk/src/cdk_lightning/mod.rs b/crates/cdk/src/cdk_lightning/mod.rs index 349459ef..0b64e836 100644 --- a/crates/cdk/src/cdk_lightning/mod.rs +++ b/crates/cdk/src/cdk_lightning/mod.rs @@ -195,10 +195,6 @@ pub struct Bolt12PaymentQuoteResponse { pub struct Settings { /// MPP supported pub mpp: bool, - /// Supports bolt12 mint - pub bolt12_mint: bool, - /// Supports bolt12 melt - pub bolt12_melt: bool, /// Base unit of backend pub unit: CurrencyUnit, /// Invoice Description supported diff --git a/crates/cdk/src/mint/builder.rs b/crates/cdk/src/mint/builder.rs index 14d70df1..ac00b4d1 100644 --- a/crates/cdk/src/mint/builder.rs +++ b/crates/cdk/src/mint/builder.rs @@ -7,13 +7,14 @@ use anyhow::anyhow; use crate::amount::Amount; use crate::cdk_database::{self, MintDatabase}; +use crate::cdk_lightning::bolt12::MintBolt12Lightning; use crate::cdk_lightning::{self, MintLightning}; use crate::mint::Mint; use crate::nuts::{ ContactInfo, CurrencyUnit, MeltMethodSettings, MintInfo, MintMethodSettings, MintVersion, MppMethodSettings, PaymentMethod, }; -use crate::types::{LnKey, QuoteTTL}; +use crate::types::QuoteTTL; /// Cashu Mint #[derive(Default)] @@ -24,8 +25,17 @@ pub struct MintBuilder { mint_info: MintInfo, /// Mint Storage backend localstore: Option + Send + Sync>>, - /// Ln backends for mint - ln: Option + Send + Sync>>>, + /// Bolt11 ln backends for mint + ln: Option< + HashMap + Send + Sync>>, + >, + /// Bolt12 backends for mint + bolt12_backends: Option< + HashMap< + CurrencyUnit, + Arc + Send + Sync>, + >, + >, seed: Option>, quote_ttl: Option, supported_units: HashMap, @@ -106,19 +116,15 @@ impl MintBuilder { pub fn add_ln_backend( mut self, unit: CurrencyUnit, - method: PaymentMethod, limits: MintMeltLimits, ln_backend: Arc + Send + Sync>, ) -> Self { - let ln_key = LnKey { - unit: unit.clone(), - method, - }; - let mut ln = self.ln.unwrap_or_default(); let settings = ln_backend.get_settings(); + let method = PaymentMethod::Bolt11; + if settings.mpp { let mpp_settings = MppMethodSettings { method, @@ -132,64 +138,32 @@ impl MintBuilder { self.mint_info.nuts.nut15 = Some(mpp); } - match method { - PaymentMethod::Bolt11 => { - let mint_method_settings = MintMethodSettings { - method, - unit: unit.clone(), - min_amount: Some(limits.mint_min), - max_amount: Some(limits.mint_max), - description: settings.invoice_description, - }; - - self.mint_info.nuts.nut04.methods.push(mint_method_settings); - self.mint_info.nuts.nut04.disabled = false; - - let melt_method_settings = MeltMethodSettings { - method, - unit, - min_amount: Some(limits.melt_min), - max_amount: Some(limits.melt_max), - }; - self.mint_info.nuts.nut05.methods.push(melt_method_settings); - self.mint_info.nuts.nut05.disabled = false; - } - PaymentMethod::Bolt12 => { - let mint_method_settings = MintMethodSettings { - method, - unit: unit.clone(), - min_amount: Some(limits.mint_min), - max_amount: Some(limits.mint_max), - description: settings.invoice_description, - }; - - let mut nut18_settings = self.mint_info.nuts.nut18.unwrap_or_default(); - - nut18_settings.methods.push(mint_method_settings); - nut18_settings.disabled = false; - - self.mint_info.nuts.nut18 = Some(nut18_settings); - - let melt_method_settings = MeltMethodSettings { - method, - unit: unit.clone(), - min_amount: Some(limits.melt_min), - max_amount: Some(limits.melt_max), - }; - - let mut nut19_settings = self.mint_info.nuts.nut19.unwrap_or_default(); - nut19_settings.methods.push(melt_method_settings); - nut19_settings.disabled = false; - - self.mint_info.nuts.nut19 = Some(nut19_settings); - } - } + let mint_method_settings = MintMethodSettings { + method, + unit: unit.clone(), + min_amount: Some(limits.mint_min), + max_amount: Some(limits.mint_max), + description: settings.invoice_description, + }; + + self.mint_info.nuts.nut04.methods.push(mint_method_settings); + self.mint_info.nuts.nut04.disabled = false; + + let melt_method_settings = MeltMethodSettings { + method, + unit: unit.clone(), + min_amount: Some(limits.melt_min), + max_amount: Some(limits.melt_max), + }; + self.mint_info.nuts.nut05.methods.push(melt_method_settings); + self.mint_info.nuts.nut05.disabled = false; - ln.insert(ln_key.clone(), ln_backend); + ln.insert(unit.clone(), ln_backend); let mut supported_units = self.supported_units.clone(); - supported_units.insert(ln_key.unit, (0, 32)); + // TODO: The max order and fee should be configutable + supported_units.insert(unit, (0, 32)); self.supported_units = supported_units; self.ln = Some(ln); @@ -197,6 +171,58 @@ impl MintBuilder { self } + /// Add ln backend + pub fn add_bolt12_ln_backend( + mut self, + unit: CurrencyUnit, + limits: MintMeltLimits, + ln_backend: Arc + Send + Sync>, + ) -> Self { + let mut ln = self.bolt12_backends.unwrap_or_default(); + + let method = PaymentMethod::Bolt12; + + let mint_method_settings = MintMethodSettings { + method, + unit: unit.clone(), + min_amount: Some(limits.mint_min), + max_amount: Some(limits.mint_max), + description: true, + }; + + let mut nut18_settings = self.mint_info.nuts.nut18.unwrap_or_default(); + + nut18_settings.methods.push(mint_method_settings); + nut18_settings.disabled = false; + + self.mint_info.nuts.nut18 = Some(nut18_settings); + + let melt_method_settings = MeltMethodSettings { + method, + unit: unit.clone(), + min_amount: Some(limits.melt_min), + max_amount: Some(limits.melt_max), + }; + + let mut nut19_settings = self.mint_info.nuts.nut19.unwrap_or_default(); + nut19_settings.methods.push(melt_method_settings); + nut19_settings.disabled = false; + + self.mint_info.nuts.nut19 = Some(nut19_settings); + + ln.insert(unit.clone(), ln_backend); + + let mut supported_units = self.supported_units.clone(); + + // TODO: The max order and fee should be configutable + supported_units.insert(unit, (0, 32)); + self.supported_units = supported_units; + + self.bolt12_backends = Some(ln); + + self + } + /// Set quote ttl pub fn with_quote_ttl(mut self, mint_ttl: u64, melt_ttl: u64) -> Self { let quote_ttl = QuoteTTL { mint_ttl, melt_ttl }; diff --git a/crates/cdk/src/mint/melt.rs b/crates/cdk/src/mint/melt.rs index ce5417cd..d3986e28 100644 --- a/crates/cdk/src/mint/melt.rs +++ b/crates/cdk/src/mint/melt.rs @@ -18,7 +18,6 @@ use crate::mint::SigFlag; use crate::nuts::nut00::ProofsMethods; use crate::nuts::nut11::{enforce_sig_flag, EnforceSigFlag}; use crate::nuts::{Id, MeltQuoteState, PublicKey}; -use crate::types::LnKey; use crate::util::unix_time; use crate::{cdk_lightning, Amount, Error}; @@ -77,14 +76,11 @@ impl Mint { self.check_melt_request_acceptable(amount, unit.clone(), PaymentMethod::Bolt11)?; - let ln = self - .ln - .get(&LnKey::new(unit.clone(), PaymentMethod::Bolt11)) - .ok_or_else(|| { - tracing::info!("Could not get ln backend for {}, bolt11 ", unit); + let ln = self.ln.get(&unit).ok_or_else(|| { + tracing::info!("Could not get ln backend for {}, bolt11 ", unit); - Error::UnitUnsupported - })?; + Error::UnitUnsupported + })?; let payment_quote = ln.get_payment_quote(melt_request).await.map_err(|err| { tracing::error!( @@ -143,14 +139,11 @@ impl Mint { self.check_melt_request_acceptable(amount, unit.clone(), PaymentMethod::Bolt12)?; - let ln = self - .bolt12_backends - .get(&LnKey::new(unit.clone(), PaymentMethod::Bolt12)) - .ok_or_else(|| { - tracing::info!("Could not get ln backend for {}, bolt11 ", unit); + let ln = self.bolt12_backends.get(&unit).ok_or_else(|| { + tracing::info!("Could not get ln backend for {}, bolt11 ", unit); - Error::UnitUnsupported - })?; + Error::UnitUnsupported + })?; let payment_quote = ln .get_bolt12_payment_quote(melt_request) @@ -552,10 +545,7 @@ impl Mint { } _ => None, }; - let ln = match self - .ln - .get(&LnKey::new(quote.unit.clone(), PaymentMethod::Bolt11)) - { + let ln = match self.ln.get("e.unit) { Some(ln) => ln, None => { tracing::info!("Could not get ln backend for {}, bolt11 ", quote.unit); @@ -569,10 +559,7 @@ impl Mint { let attempt_to_pay = match melt_request.get_payment_method() { PaymentMethod::Bolt11 => { - let ln = match self - .ln - .get(&LnKey::new(quote.unit.clone(), PaymentMethod::Bolt11)) - { + let ln = match self.ln.get("e.unit) { Some(ln) => ln, None => { tracing::info!( @@ -590,10 +577,7 @@ impl Mint { .await } PaymentMethod::Bolt12 => { - let ln = match self - .bolt12_backends - .get(&LnKey::new(quote.unit.clone(), PaymentMethod::Bolt12)) - { + let ln = match self.bolt12_backends.get("e.unit) { Some(ln) => ln, None => { tracing::info!( diff --git a/crates/cdk/src/mint/mint_18.rs b/crates/cdk/src/mint/mint_18.rs index 827b3bd3..447a6da3 100644 --- a/crates/cdk/src/mint/mint_18.rs +++ b/crates/cdk/src/mint/mint_18.rs @@ -2,7 +2,6 @@ use tracing::instrument; use super::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response}; use super::{Mint, MintQuote, PaymentMethod}; -use crate::types::LnKey; use crate::util::unix_time; use crate::{Amount, Error}; @@ -32,14 +31,11 @@ impl Mint { return Err(Error::MintingDisabled); } - let ln = self - .bolt12_backends - .get(&LnKey::new(unit.clone(), PaymentMethod::Bolt12)) - .ok_or_else(|| { - tracing::info!("Bolt11 mint request for unsupported unit"); + let ln = self.bolt12_backends.get(&unit).ok_or_else(|| { + tracing::info!("Bolt11 mint request for unsupported unit"); - Error::UnitUnsupported - })?; + Error::UnitUnsupported + })?; let quote_expiry = match expiry { Some(expiry) => expiry, diff --git a/crates/cdk/src/mint/mint_nut04.rs b/crates/cdk/src/mint/mint_nut04.rs index 551500ca..68296140 100644 --- a/crates/cdk/src/mint/mint_nut04.rs +++ b/crates/cdk/src/mint/mint_nut04.rs @@ -6,7 +6,6 @@ use super::{ }; use crate::cdk_lightning::WaitInvoiceResponse; use crate::nuts::MintQuoteState; -use crate::types::LnKey; use crate::util::unix_time; use crate::{Amount, Error}; @@ -69,14 +68,11 @@ impl Mint { self.check_mint_request_acceptable(amount, &unit)?; - let ln = self - .ln - .get(&LnKey::new(unit.clone(), PaymentMethod::Bolt11)) - .ok_or_else(|| { - tracing::info!("Bolt11 mint request for unsupported unit"); + let ln = self.ln.get(&unit).ok_or_else(|| { + tracing::info!("Bolt11 mint request for unsupported unit"); - Error::UnitUnsupported - })?; + Error::UnitUnsupported + })?; let quote_expiry = unix_time() + self.quote_ttl.mint_ttl; diff --git a/crates/cdk/src/mint/mod.rs b/crates/cdk/src/mint/mod.rs index a7bb5e57..58c5a206 100644 --- a/crates/cdk/src/mint/mod.rs +++ b/crates/cdk/src/mint/mod.rs @@ -21,7 +21,7 @@ use crate::error::Error; use crate::fees::calculate_fee; use crate::mint_url::MintUrl; use crate::nuts::*; -use crate::types::{LnKey, QuoteTTL}; +use crate::types::QuoteTTL; use crate::util::unix_time; use crate::Amount; @@ -50,10 +50,12 @@ pub struct Mint { /// Mint Storage backend pub localstore: Arc + Send + Sync>, /// Ln backends for mint - pub ln: HashMap + Send + Sync>>, + pub ln: HashMap + Send + Sync>>, /// Ln backends for mint - pub bolt12_backends: - HashMap + Send + Sync>>, + pub bolt12_backends: HashMap< + CurrencyUnit, + Arc + Send + Sync>, + >, /// Subscription manager pub pubsub_manager: Arc, /// Active Mint Keysets @@ -71,9 +73,9 @@ impl Mint { mint_info: MintInfo, quote_ttl: QuoteTTL, localstore: Arc + Send + Sync>, - ln: HashMap + Send + Sync>>, + ln: HashMap + Send + Sync>>, bolt12: HashMap< - LnKey, + CurrencyUnit, Arc + Send + Sync>, >, // Hashmap where the key is the unit and value is (input fee ppk, max_order) diff --git a/crates/cdk/src/types.rs b/crates/cdk/src/types.rs index 23ab9e89..4869b235 100644 --- a/crates/cdk/src/types.rs +++ b/crates/cdk/src/types.rs @@ -141,6 +141,7 @@ impl ProofInfo { /// Key used in hashmap of ln backends to identify what unit and payment method /// it is for +// TODO: Check if this is actually used anywhere #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct LnKey { /// Unit of Payment backend