From 7afd88b40a312e597f74a0295b87b204ffc43808 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Sun, 1 Dec 2024 14:03:14 +0000 Subject: [PATCH] fix(mintd/nut06): signal support for opt nuts --- crates/cdk-mintd/src/main.rs | 25 ++++++++++++++++++++++++- crates/cdk/src/mint/builder.rs | 30 +++++++++++++++++++++++++++++- crates/cdk/src/nuts/nut06.rs | 11 +++++++++++ crates/cdk/src/nuts/nut17/mod.rs | 30 +++++++++++++++++++++++++----- 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/crates/cdk-mintd/src/main.rs b/crates/cdk-mintd/src/main.rs index 325ddd93..3d789c8d 100644 --- a/crates/cdk-mintd/src/main.rs +++ b/crates/cdk-mintd/src/main.rs @@ -15,6 +15,7 @@ use cdk::cdk_database::{self, MintDatabase}; use cdk::cdk_lightning; use cdk::cdk_lightning::MintLightning; use cdk::mint::{MintBuilder, MintMeltLimits}; +use cdk::nuts::nut17::SupportedMethods; use cdk::nuts::{ContactInfo, CurrencyUnit, MintVersion, PaymentMethod}; use cdk::types::LnKey; use cdk_mintd::cli::CLIArgs; @@ -150,6 +151,10 @@ async fn main() -> anyhow::Result<()> { mint_melt_limits, cln.clone(), ); + + let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, CurrencyUnit::Sat); + + mint_builder = mint_builder.add_supported_websockets(nut17_supported); } LnBackend::Strike => { let strike_settings = settings.clone().strike.expect("Checked on config load"); @@ -164,11 +169,14 @@ async fn main() -> anyhow::Result<()> { .await?; mint_builder = mint_builder.add_ln_backend( - unit, + unit.clone(), PaymentMethod::Bolt11, mint_melt_limits, Arc::new(strike), ); + let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, unit); + + mint_builder = mint_builder.add_supported_websockets(nut17_supported); } } LnBackend::LNbits => { @@ -183,6 +191,9 @@ async fn main() -> anyhow::Result<()> { mint_melt_limits, Arc::new(lnbits), ); + let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, CurrencyUnit::Sat); + + mint_builder = mint_builder.add_supported_websockets(nut17_supported); } LnBackend::Phoenixd => { let phd_settings = settings.clone().phoenixd.expect("Checked at config load"); @@ -196,6 +207,10 @@ async fn main() -> anyhow::Result<()> { mint_melt_limits, Arc::new(phd), ); + + let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, CurrencyUnit::Sat); + + mint_builder = mint_builder.add_supported_websockets(nut17_supported); } LnBackend::Lnd => { let lnd_settings = settings.clone().lnd.expect("Checked at config load"); @@ -209,6 +224,10 @@ async fn main() -> anyhow::Result<()> { mint_melt_limits, Arc::new(lnd), ); + + let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, CurrencyUnit::Sat); + + mint_builder = mint_builder.add_supported_websockets(nut17_supported); } LnBackend::FakeWallet => { let fake_wallet = settings.clone().fake_wallet.expect("Fake wallet defined"); @@ -226,6 +245,10 @@ async fn main() -> anyhow::Result<()> { mint_melt_limits, fake.clone(), ); + + let nut17_supported = SupportedMethods::new(PaymentMethod::Bolt11, unit); + + mint_builder = mint_builder.add_supported_websockets(nut17_supported); } } }; diff --git a/crates/cdk/src/mint/builder.rs b/crates/cdk/src/mint/builder.rs index a71c259c..989ddd99 100644 --- a/crates/cdk/src/mint/builder.rs +++ b/crates/cdk/src/mint/builder.rs @@ -5,6 +5,8 @@ use std::sync::Arc; use anyhow::anyhow; +use super::nut17::SupportedMethods; +use super::Nuts; use crate::amount::Amount; use crate::cdk_database::{self, MintDatabase}; use crate::cdk_lightning::{self, MintLightning}; @@ -34,7 +36,20 @@ pub struct MintBuilder { impl MintBuilder { /// New mint builder pub fn new() -> MintBuilder { - MintBuilder::default() + let mut builder = MintBuilder::default(); + + let nuts = Nuts::new() + .nut07(true) + .nut08(true) + .nut09(true) + .nut10(true) + .nut11(true) + .nut12(true) + .nut14(true); + + builder.mint_info.nuts = nuts; + + builder } /// Set localstore @@ -184,6 +199,19 @@ impl MintBuilder { self } + /// Support websockets + pub fn add_supported_websockets(mut self, supported_method: SupportedMethods) -> Self { + let mut supported_settings = self.mint_info.nuts.nut17.supported.clone(); + + if !supported_settings.contains(&supported_method) { + supported_settings.push(supported_method); + + self.mint_info.nuts = self.mint_info.nuts.nut17(supported_settings); + } + + self + } + /// Build mint pub async fn build(&self) -> anyhow::Result { Ok(Mint::new( diff --git a/crates/cdk/src/nuts/nut06.rs b/crates/cdk/src/nuts/nut06.rs index 17ba18b6..56f91d24 100644 --- a/crates/cdk/src/nuts/nut06.rs +++ b/crates/cdk/src/nuts/nut06.rs @@ -5,6 +5,8 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; use super::nut01::PublicKey; +#[cfg(feature = "mint")] +use super::nut17::SupportedMethods; use super::{nut04, nut05, nut15, MppMethodSettings}; /// Mint Version @@ -329,6 +331,15 @@ impl Nuts { ..self } } + + /// Nut17 settings + #[cfg(feature = "mint")] + pub fn nut17(self, supported: Vec) -> Self { + Self { + nut17: super::nut17::SupportedSettings { supported }, + ..self + } + } } /// Check state Settings diff --git a/crates/cdk/src/nuts/nut17/mod.rs b/crates/cdk/src/nuts/nut17/mod.rs index 3ddd1f82..8fbdf413 100644 --- a/crates/cdk/src/nuts/nut17/mod.rs +++ b/crates/cdk/src/nuts/nut17/mod.rs @@ -32,7 +32,8 @@ pub struct Params { /// Check state Settings #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct SupportedSettings { - supported: Vec, + /// Supported methods + pub supported: Vec, } impl Default for SupportedSettings { @@ -43,11 +44,30 @@ impl Default for SupportedSettings { } } +/// Supported WS Methods #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -struct SupportedMethods { - method: PaymentMethod, - unit: CurrencyUnit, - commands: Vec, +pub struct SupportedMethods { + /// Payment Method + pub method: PaymentMethod, + /// Unit + pub unit: CurrencyUnit, + /// Command + pub commands: Vec, +} + +impl SupportedMethods { + /// Create [`SupportedMethods`] + pub fn new(method: PaymentMethod, unit: CurrencyUnit) -> Self { + Self { + method, + unit, + commands: vec![ + "bolt11_mint_quote".to_owned(), + "bolt11_melt_quote".to_owned(), + "proof_state".to_owned(), + ], + } + } } impl Default for SupportedMethods {