Skip to content

Commit

Permalink
fix(mintd/nut06): signal support for opt nuts
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Dec 2, 2024
1 parent 7a0a170 commit 7afd88b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 7 deletions.
25 changes: 24 additions & 1 deletion crates/cdk-mintd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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 => {
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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);
}
}
};
Expand Down
30 changes: 29 additions & 1 deletion crates/cdk/src/mint/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Mint> {
Ok(Mint::new(
Expand Down
11 changes: 11 additions & 0 deletions crates/cdk/src/nuts/nut06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -329,6 +331,15 @@ impl Nuts {
..self
}
}

/// Nut17 settings
#[cfg(feature = "mint")]
pub fn nut17(self, supported: Vec<SupportedMethods>) -> Self {
Self {
nut17: super::nut17::SupportedSettings { supported },
..self
}
}
}

/// Check state Settings
Expand Down
30 changes: 25 additions & 5 deletions crates/cdk/src/nuts/nut17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ pub struct Params {
/// Check state Settings
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct SupportedSettings {
supported: Vec<SupportedMethods>,
/// Supported methods
pub supported: Vec<SupportedMethods>,
}

impl Default for SupportedSettings {
Expand All @@ -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<String>,
pub struct SupportedMethods {
/// Payment Method
pub method: PaymentMethod,
/// Unit
pub unit: CurrencyUnit,
/// Command
pub commands: Vec<String>,
}

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 {
Expand Down

0 comments on commit 7afd88b

Please sign in to comment.