Skip to content

Commit

Permalink
chore: rename btconchain endpoints to nut-18 and nut-19 fixes Rename …
Browse files Browse the repository at this point in the history
…info-endpoints for btconchain to 18 and 19

fixes #311
  • Loading branch information
ngutech21 committed Jul 29, 2024
1 parent d42128f commit 285d895
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
6 changes: 3 additions & 3 deletions moksha-cli/src/bin/moksha-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async fn main() -> anyhow::Result<()> {

let info = wallet.get_mint_info(&mint_url).await?;

if info.nuts.nut18.map_or(true, |nut18| !nut18.supported) {
if info.nuts.nut19.map_or(true, |nut18| !nut18.supported) {
term.write_line("Error: onchain-payments are not supported by this mint")?;
return Ok(());
}
Expand Down Expand Up @@ -319,7 +319,7 @@ async fn main() -> anyhow::Result<()> {

let info = wallet.get_mint_info(&mint_url).await?;

let payment_method = info.nuts.nut17.as_ref().map_or_else(
let payment_method = info.nuts.nut18.as_ref().map_or_else(
|| {
term.write_line("Only bolt11 minting is supported")
.expect("write_line failed");
Expand All @@ -346,7 +346,7 @@ async fn main() -> anyhow::Result<()> {

let quote = match payment_method {
PaymentMethod::BtcOnchain => {
let nut17 = info.nuts.nut17.expect("nut17 is None");
let nut17 = info.nuts.nut18.expect("nut17 is None");
let payment_method = nut17.payment_methods.first().expect("no payment methods");

if amount < payment_method.min_amount {
Expand Down
64 changes: 58 additions & 6 deletions moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,33 @@ pub struct Nuts {
/// DLEQ proofs
pub nut12: Option<Nut12>,

#[serde(rename = "13", skip_serializing_if = "Option::is_none")]
/// deterministic secrets
pub nut13: Option<Nut13>,

#[serde(rename = "14", skip_serializing_if = "Option::is_none")]
/// Hashed Timelock Contracts
pub nut14: Option<Nut14>,

#[serde(rename = "15", skip_serializing_if = "Option::is_none")]
/// Partial multi-path payments
pub nut15: Option<Nut15>,

#[serde(rename = "16", skip_serializing_if = "Option::is_none")]
/// Partial multi-path payments
pub nut16: Option<Nut16>,

#[serde(rename = "17", skip_serializing_if = "Option::is_none")]
/// minting tokens btc onchain
/// WebSockets
pub nut17: Option<Nut17>,

#[serde(rename = "18", skip_serializing_if = "Option::is_none")]
/// melting tokens btc onchain
/// minting tokens btc onchain
pub nut18: Option<Nut18>,

#[serde(rename = "19", skip_serializing_if = "Option::is_none")]
/// melting tokens btc onchain
pub nut19: Option<Nut19>,
}

impl Default for Nuts {
Expand All @@ -414,8 +434,13 @@ impl Default for Nuts {
nut10: Some(Nut10 { supported: false }),
nut11: Some(Nut11 { supported: false }),
nut12: Some(Nut12 { supported: false }),
nut13: Some(Nut13::default()),
nut14: Some(Nut14::default()),
nut15: Some(Nut15::default()),
nut16: Some(Nut16::default()),
nut17: Some(Nut17::default()),
nut18: Some(Nut18::default()),
nut19: Some(Nut19::default()),
}
}
}
Expand Down Expand Up @@ -498,9 +523,36 @@ pub struct Nut12 {
pub supported: bool,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)]
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Default, ToSchema)]
pub struct Nut13 {
pub supported: bool,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Default, ToSchema)]
pub struct Nut14 {
pub supported: bool,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Default, ToSchema)]
pub struct Nut15 {
pub supported: bool,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Default, ToSchema)]
pub struct Nut16 {
pub supported: bool,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, Default, ToSchema)]
pub struct Nut17 {
pub supported: bool,
}



#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)]
pub struct Nut18 {
pub supported: bool,
#[serde(rename = "methods")]
pub payment_methods: Vec<PaymentMethodConfigBtcOnchain>,
}
Expand All @@ -523,7 +575,7 @@ pub struct PaymentMethodConfigBtcOnchain {
pub max_amount: u64,
}

impl Default for Nut17 {
impl Default for Nut18 {
fn default() -> Self {
Self {
supported: true,
Expand All @@ -538,13 +590,13 @@ impl Default for Nut17 {
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)]
pub struct Nut18 {
pub struct Nut19 {
pub supported: bool,
#[serde(rename = "methods")]
pub payment_methods: Vec<PaymentMethodConfigBtcOnchain>,
}

impl Default for Nut18 {
impl Default for Nut19 {
fn default() -> Self {
Self {
supported: true,
Expand Down
6 changes: 3 additions & 3 deletions moksha-mint/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{env, net::SocketAddr, path::PathBuf, str::FromStr};

use clap::Parser;
use moksha_core::primitives::{
ContactInfoResponse, CurrencyUnit, Nut17, Nut18, PaymentMethod, PaymentMethodConfigBtcOnchain,
ContactInfoResponse, CurrencyUnit, Nut18, Nut19, PaymentMethod, PaymentMethodConfigBtcOnchain,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -209,7 +209,7 @@ impl FromStr for BtcOnchainTypeVariant {
}
}

impl From<BtcOnchainConfig> for Nut17 {
impl From<BtcOnchainConfig> for Nut18 {
fn from(settings: BtcOnchainConfig) -> Self {
Self {
supported: true,
Expand All @@ -223,7 +223,7 @@ impl From<BtcOnchainConfig> for Nut17 {
}
}

impl From<BtcOnchainConfig> for Nut18 {
impl From<BtcOnchainConfig> for Nut19 {
fn from(settings: BtcOnchainConfig) -> Self {
Self {
supported: true,
Expand Down
2 changes: 1 addition & 1 deletion moksha-mint/src/routes/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ fn get_nuts(cfg: &MintConfig) -> Nuts {
let default_config = BtcOnchainConfig::default();
let config = cfg.btconchain_backend.as_ref().unwrap_or(&default_config);
Nuts {
nut17: Some(config.to_owned().into()),
nut18: Some(config.to_owned().into()),
nut19: Some(config.to_owned().into()),
..Nuts::default()
}
}
4 changes: 2 additions & 2 deletions moksha-mint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use moksha_core::blind::BlindedMessage;
use moksha_core::blind::BlindedSignature;
use moksha_core::primitives::{
CurrencyUnit, GetMeltBtcOnchainResponse, KeyResponse, KeysResponse, MintInfoResponse, Nut10,
Nut11, Nut12, Nut17, Nut18, Nut4, Nut5, Nut7, Nut8, Nut9, Nuts, PaymentMethod,
Nut11, Nut12, Nut18, Nut19, Nut4, Nut5, Nut7, Nut8, Nut9, Nuts, PaymentMethod,
PostMeltBolt11Request, PostMeltBolt11Response, PostMeltQuoteBolt11Request,
PostMeltQuoteBolt11Response, PostMeltQuoteBtcOnchainRequest, PostMeltQuoteBtcOnchainResponse,
PostMintBolt11Request, PostMintBolt11Response, PostMintQuoteBolt11Request,
Expand Down Expand Up @@ -144,8 +144,8 @@ pub async fn run_server(mint: Mint) -> anyhow::Result<()> {
PostSwapRequest,
PostSwapResponse,
P2SHScript,
Nut17,
Nut18,
Nut19,
PostMintQuoteBtcOnchainRequest,
PostMintQuoteBtcOnchainResponse,
PostMeltQuoteBtcOnchainRequest,
Expand Down

0 comments on commit 285d895

Please sign in to comment.