Skip to content

Commit

Permalink
feat: rename to 20 and 21
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Nov 18, 2024
1 parent a04fb56 commit 558aeda
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 134 deletions.
3 changes: 1 addition & 2 deletions crates/cdk-axum/src/bolt12_router.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use anyhow::Result;
use axum::extract::{Json, Path, State};
use axum::response::Response;
use cdk::nuts::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response};
use cdk::nuts::{
MeltBolt12Request, MeltQuoteBolt11Response, MeltQuoteBolt12Request, MintBolt11Request,
MintBolt11Response,
MintBolt11Response, MintQuoteBolt12Request, MintQuoteBolt12Response,
};

use crate::{into_response, MintState};
Expand Down
3 changes: 1 addition & 2 deletions crates/cdk/src/cdk_lightning/bolt12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use serde::{Deserialize, Serialize};
use super::{
Bolt12PaymentQuoteResponse, CreateOfferResponse, Error, PayInvoiceResponse, WaitInvoiceResponse,
};
use crate::nuts::nut20::MeltQuoteBolt12Request;
use crate::nuts::CurrencyUnit;
use crate::nuts::{CurrencyUnit, MeltQuoteBolt12Request};
use crate::{mint, Amount};

/// MintLighting Bolt12 Trait
Expand Down
4 changes: 2 additions & 2 deletions crates/cdk/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ pub enum Error {
NUT18(#[from] crate::nuts::nut18::Error),
/// NUT19 Error
#[error(transparent)]
NUT19(#[from] crate::nuts::nut19::Error),
NUT19(#[from] crate::nuts::nut20::Error),
/// NUT18 Error
#[error(transparent)]
NUT20(#[from] crate::nuts::nut20::Error),
NUT20(#[from] crate::nuts::nut21::Error),
/// Database Error
#[cfg(any(feature = "wallet", feature = "mint"))]
#[error(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion crates/cdk/src/mint/mint_18.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tracing::instrument;

use super::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response};
use super::nut20::{MintQuoteBolt12Request, MintQuoteBolt12Response};
use super::{Mint, MintQuote, PaymentMethod};
use crate::util::unix_time;
use crate::{Amount, Error};
Expand Down
5 changes: 3 additions & 2 deletions crates/cdk/src/nuts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub mod nut15;
#[cfg(feature = "mint")]
pub mod nut17;
pub mod nut18;
pub mod nut19;
pub mod nut20;
pub mod nut21;

pub use nut00::{
BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod, PreMint, PreMintSecrets, Proof,
Expand Down Expand Up @@ -54,4 +54,5 @@ pub use nut15::{Mpp, MppMethodSettings, Settings as NUT15Settings};
#[cfg(feature = "mint")]
pub use nut17::{NotificationPayload, PubSubManager};
pub use nut18::{PaymentRequest, PaymentRequestPayload, Transport};
pub use nut20::{MeltBolt12Request, MeltQuoteBolt12Request};
pub use nut20::{MintQuoteBolt12Request, MintQuoteBolt12Response};
pub use nut21::{MeltBolt12Request, MeltQuoteBolt12Request};
66 changes: 0 additions & 66 deletions crates/cdk/src/nuts/nut19.rs

This file was deleted.

97 changes: 43 additions & 54 deletions crates/cdk/src/nuts/nut20.rs
Original file line number Diff line number Diff line change
@@ -1,77 +1,66 @@
//! Bolt12
//! NUT-17: Mint Tokens via Bolt11
//!
//! <https://github.com/cashubtc/nuts/blob/main/04.md>
use serde::{Deserialize, Serialize};
use thiserror::Error;

use super::nut05::MeltRequestTrait;
use super::{BlindedMessage, CurrencyUnit, PaymentMethod, Proofs};
use super::nut00::CurrencyUnit;
use crate::Amount;

/// NUT18 Error
/// NUT04 Error
#[derive(Debug, Error)]
pub enum Error {
/// Unknown Quote State
#[error("Unknown quote state")]
#[error("Unknown Quote State")]
UnknownState,
/// Amount overflow
#[error("Amount Overflow")]
#[error("Amount overflow")]
AmountOverflow,
}

/// Melt quote request [NUT-18]
/// Mint quote request [NUT-19]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub struct MeltQuoteBolt12Request {
/// Bolt12 invoice to be paid
pub request: String,
pub struct MintQuoteBolt12Request {
/// Amount
pub amount: Option<Amount>,
/// Unit wallet would like to pay with
pub unit: CurrencyUnit,
/// Payment Options
pub amount: Option<Amount>,
/// Memo to create the invoice with
pub description: Option<String>,
/// Single use
pub single_use: bool,
/// Expiry
pub expiry: Option<u64>,
}

/// Melt Bolt12 Request [NUT-18]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MeltBolt12Request {
/// Quote ID
/// Mint quote response [NUT-19]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub struct MintQuoteBolt12Response {
/// Quote Id
pub quote: String,
/// Proofs
pub inputs: Proofs,
/// Blinded Message that can be used to return change [NUT-08]
/// Amount field of BlindedMessages `SHOULD` be set to zero
pub outputs: Option<Vec<BlindedMessage>>,
/// Payment request to fulfil
pub request: String,
/// Single use
pub single_use: bool,
/// Unix timestamp until the quote is valid
pub expiry: Option<u64>,
/// Amount that has been paid
pub amount_paid: Amount,
/// Amount that has been issued
pub amount_issued: Amount,
}

impl MeltRequestTrait for MeltBolt12Request {
type Err = Error;

fn get_quote_id(&self) -> &str {
&self.quote
}

fn get_inputs(&self) -> &Proofs {
&self.inputs
}

fn get_outputs(&self) -> &Option<Vec<BlindedMessage>> {
&self.outputs
}

fn inputs_amount(&self) -> Result<Amount, Error> {
Amount::try_sum(self.inputs.iter().map(|proof| proof.amount))
.map_err(|_| Error::AmountOverflow)
}

fn outputs_amount(&self) -> Result<Amount, Error> {
Amount::try_sum(
self.outputs
.as_ref()
.unwrap_or(&vec![])
.iter()
.map(|proof| proof.amount),
)
.map_err(|_| Error::AmountOverflow)
}

fn get_payment_method(&self) -> PaymentMethod {
PaymentMethod::Bolt12
#[cfg(feature = "mint")]
impl From<crate::mint::MintQuote> for MintQuoteBolt12Response {
fn from(mint_quote: crate::mint::MintQuote) -> MintQuoteBolt12Response {
MintQuoteBolt12Response {
quote: mint_quote.id,
request: mint_quote.request,
expiry: Some(mint_quote.expiry),
amount_paid: mint_quote.amount_paid,
amount_issued: mint_quote.amount_issued,
single_use: mint_quote.single_use,
}
}
}
77 changes: 77 additions & 0 deletions crates/cdk/src/nuts/nut21.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! Bolt12
use serde::{Deserialize, Serialize};
use thiserror::Error;

use super::nut05::MeltRequestTrait;
use super::{BlindedMessage, CurrencyUnit, PaymentMethod, Proofs};
use crate::Amount;

/// NUT18 Error
#[derive(Debug, Error)]
pub enum Error {
/// Unknown Quote State
#[error("Unknown quote state")]
UnknownState,
/// Amount overflow
#[error("Amount Overflow")]
AmountOverflow,
}

/// Melt quote request [NUT-18]
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub struct MeltQuoteBolt12Request {
/// Bolt12 invoice to be paid
pub request: String,
/// Unit wallet would like to pay with
pub unit: CurrencyUnit,
/// Payment Options
pub amount: Option<Amount>,
}

/// Melt Bolt12 Request [NUT-18]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MeltBolt12Request {
/// Quote ID
pub quote: String,
/// Proofs
pub inputs: Proofs,
/// Blinded Message that can be used to return change [NUT-08]
/// Amount field of BlindedMessages `SHOULD` be set to zero
pub outputs: Option<Vec<BlindedMessage>>,
}

impl MeltRequestTrait for MeltBolt12Request {
type Err = Error;

fn get_quote_id(&self) -> &str {
&self.quote
}

fn get_inputs(&self) -> &Proofs {
&self.inputs
}

fn get_outputs(&self) -> &Option<Vec<BlindedMessage>> {
&self.outputs
}

fn inputs_amount(&self) -> Result<Amount, Error> {
Amount::try_sum(self.inputs.iter().map(|proof| proof.amount))
.map_err(|_| Error::AmountOverflow)
}

fn outputs_amount(&self) -> Result<Amount, Error> {
Amount::try_sum(
self.outputs
.as_ref()
.unwrap_or(&vec![])
.iter()
.map(|proof| proof.amount),
)
.map_err(|_| Error::AmountOverflow)
}

fn get_payment_method(&self) -> PaymentMethod {
PaymentMethod::Bolt12
}
}
6 changes: 3 additions & 3 deletions crates/cdk/src/wallet/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use url::Url;
use super::Error;
use crate::error::ErrorResponse;
use crate::mint_url::MintUrl;
use crate::nuts::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response};
use crate::nuts::{
BlindedMessage, CheckStateRequest, CheckStateResponse, CurrencyUnit, Id, KeySet, KeysResponse,
KeysetResponse, MeltBolt11Request, MeltBolt12Request, MeltQuoteBolt11Request,
MeltQuoteBolt11Response, MeltQuoteBolt12Request, MintBolt11Request, MintBolt11Response,
MintInfo, MintQuoteBolt11Request, MintQuoteBolt11Response, PreMintSecrets, Proof,
RestoreRequest, RestoreResponse, SwapRequest, SwapResponse,
MintInfo, MintQuoteBolt11Request, MintQuoteBolt11Response, MintQuoteBolt12Request,
MintQuoteBolt12Response, PreMintSecrets, Proof, RestoreRequest, RestoreResponse, SwapRequest,
SwapResponse,
};
use crate::Amount;

Expand Down
4 changes: 2 additions & 2 deletions crates/cdk/src/wallet/mint_bolt12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use super::MintQuote;
use crate::amount::SplitTarget;
use crate::dhke::construct_proofs;
use crate::nuts::nut00::ProofsMethods;
use crate::nuts::nut19::{MintQuoteBolt12Request, MintQuoteBolt12Response};
use crate::nuts::{
nut12, MintBolt11Request, PaymentMethod, PreMintSecrets, SpendingConditions, State,
nut12, MintBolt11Request, MintQuoteBolt12Request, MintQuoteBolt12Response, PaymentMethod,
PreMintSecrets, SpendingConditions, State,
};
use crate::types::ProofInfo;
use crate::util::unix_time;
Expand Down

0 comments on commit 558aeda

Please sign in to comment.