Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mint): signal support for opt nuts #483

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading