Skip to content

Commit

Permalink
feat: add new mint/melt method settings (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Mar 21, 2024
1 parent ca7225c commit a11c1d6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
24 changes: 22 additions & 2 deletions moksha-core/src/fixtures/nutshell_mint_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,28 @@
],
"motd": "Message to users",
"nuts": {
"4": { "methods": [["bolt11", "sat"]], "disabled": false },
"5": { "methods": [["bolt11", "sat"]], "disabled": false },
"4": {
"methods": [
{
"method": "bolt11",
"unit": "sat",
"min_amount": 1,
"max_amount": 21
}
],
"disabled": false
},
"5": {
"methods": [
{
"method": "bolt11",
"unit": "sat",
"min_amount": 1,
"max_amount": 42
}
],
"disabled": false
},
"7": { "supported": true },
"8": { "supported": true },
"9": { "supported": true },
Expand Down
40 changes: 32 additions & 8 deletions moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,28 +423,42 @@ pub struct Nuts {

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)]
pub struct Nut4 {
pub methods: Vec<(PaymentMethod, CurrencyUnit)>,
#[serde(rename = "methods")]
pub payment_methods: Vec<PaymentMethodConfig>,
pub disabled: bool,
}

impl Default for Nut4 {
fn default() -> Self {
Self {
methods: vec![(PaymentMethod::Bolt11, CurrencyUnit::Sat)],
payment_methods: vec![PaymentMethodConfig {
payment_method: PaymentMethod::Bolt11,
unit: CurrencyUnit::Sat,
min_amount: Some(1),
max_amount: Some(10_000_000),
}],
disabled: false,
}
}
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)]
pub struct Nut5 {
pub methods: Vec<(PaymentMethod, CurrencyUnit)>,
#[serde(rename = "methods")]
pub payment_methods: Vec<PaymentMethodConfig>,
pub disabled: bool,
}

impl Default for Nut5 {
fn default() -> Self {
Self {
methods: vec![(PaymentMethod::Bolt11, CurrencyUnit::Sat)],
payment_methods: vec![PaymentMethodConfig {
payment_method: PaymentMethod::Bolt11,
unit: CurrencyUnit::Sat,
min_amount: Some(1),
max_amount: Some(10_000_000),
}],
disabled: false,
}
}
}
Expand Down Expand Up @@ -489,11 +503,21 @@ pub struct Nut12 {
pub struct Nut14 {
pub supported: bool,
#[serde(rename = "methods")]
pub payment_methods: Vec<PaymentMethodConfig>,
pub payment_methods: Vec<PaymentMethodConfigBtcOnchain>,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)]
pub struct PaymentMethodConfig {
#[serde(rename = "method")]
pub payment_method: PaymentMethod,
pub unit: CurrencyUnit,
pub min_amount: Option<u64>,
pub max_amount: Option<u64>,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)]
pub struct PaymentMethodConfigBtcOnchain {
#[serde(rename = "method")]
pub payment_method: PaymentMethod,
pub unit: CurrencyUnit,
pub min_amount: u64,
Expand All @@ -504,7 +528,7 @@ impl Default for Nut14 {
fn default() -> Self {
Self {
supported: true,
payment_methods: vec![PaymentMethodConfig {
payment_methods: vec![PaymentMethodConfigBtcOnchain {
payment_method: PaymentMethod::BtcOnchain,
unit: CurrencyUnit::Sat,
min_amount: 1_000,
Expand All @@ -518,14 +542,14 @@ impl Default for Nut14 {
pub struct Nut15 {
pub supported: bool,
#[serde(rename = "methods")]
pub payment_methods: Vec<PaymentMethodConfig>,
pub payment_methods: Vec<PaymentMethodConfigBtcOnchain>,
}

impl Default for Nut15 {
fn default() -> Self {
Self {
supported: true,
payment_methods: vec![PaymentMethodConfig {
payment_methods: vec![PaymentMethodConfigBtcOnchain {
payment_method: PaymentMethod::BtcOnchain,
unit: CurrencyUnit::Sat,
min_amount: 1_000,
Expand Down
8 changes: 5 additions & 3 deletions moksha-mint/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{env, net::SocketAddr, path::PathBuf, str::FromStr};

use clap::Parser;
use moksha_core::primitives::{CurrencyUnit, Nut14, Nut15, PaymentMethod, PaymentMethodConfig};
use moksha_core::primitives::{
CurrencyUnit, Nut14, Nut15, PaymentMethod, PaymentMethodConfigBtcOnchain,
};
use serde::{Deserialize, Serialize};

use crate::lightning::{
Expand Down Expand Up @@ -211,7 +213,7 @@ impl From<BtcOnchainConfig> for Nut14 {
fn from(settings: BtcOnchainConfig) -> Self {
Self {
supported: true,
payment_methods: vec![PaymentMethodConfig {
payment_methods: vec![PaymentMethodConfigBtcOnchain {
payment_method: PaymentMethod::BtcOnchain,
unit: CurrencyUnit::Sat,
min_amount: settings.min_amount,
Expand All @@ -225,7 +227,7 @@ impl From<BtcOnchainConfig> for Nut15 {
fn from(settings: BtcOnchainConfig) -> Self {
Self {
supported: true,
payment_methods: vec![PaymentMethodConfig {
payment_methods: vec![PaymentMethodConfigBtcOnchain {
payment_method: PaymentMethod::BtcOnchain,
unit: CurrencyUnit::Sat,
min_amount: settings.min_amount,
Expand Down

0 comments on commit a11c1d6

Please sign in to comment.