Skip to content

Commit

Permalink
feat: remove old nut05 response
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Oct 3, 2024
1 parent e54548b commit 27eed93
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 41 deletions.
3 changes: 1 addition & 2 deletions crates/cdk-axum/src/router_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use axum::extract::{Json, Path, State};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use cdk::error::ErrorResponse;
use cdk::nuts::nut05::MeltBolt11Response;
use cdk::nuts::{
CheckStateRequest, CheckStateResponse, Id, KeysResponse, KeysetResponse, MeltBolt11Request,
MeltQuoteBolt11Request, MeltQuoteBolt11Response, MintBolt11Request, MintBolt11Response,
Expand Down Expand Up @@ -121,7 +120,7 @@ pub async fn get_check_melt_bolt11_quote(
pub async fn post_melt_bolt11(
State(state): State<MintState>,
Json(payload): Json<MeltBolt11Request>,
) -> Result<Json<MeltBolt11Response>, Response> {
) -> Result<Json<MeltQuoteBolt11Response>, Response> {
let res = state
.mint
.melt_bolt11(&payload)
Expand Down
5 changes: 2 additions & 3 deletions crates/cdk/src/mint/melt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{
Amount, Error,
};

use super::nut05::MeltBolt11Response;
use super::{
CurrencyUnit, MeltBolt11Request, MeltQuote, MeltQuoteBolt11Request, MeltQuoteBolt11Response,
Mint, PaymentMethod, PublicKey, State,
Expand Down Expand Up @@ -397,7 +396,7 @@ impl Mint {
pub async fn melt_bolt11(
&self,
melt_request: &MeltBolt11Request,
) -> Result<MeltBolt11Response, Error> {
) -> Result<MeltQuoteBolt11Response, Error> {
use std::sync::Arc;
async fn check_payment_state(
ln: Arc<dyn MintLightning<Err = cdk_lightning::Error> + Send + Sync>,
Expand Down Expand Up @@ -595,7 +594,7 @@ impl Mint {
err
})?;

Ok(res.into())
Ok(res)
}

/// Process melt request marking [`Proofs`] as spent
Expand Down
22 changes: 0 additions & 22 deletions crates/cdk/src/nuts/nut05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,28 +227,6 @@ impl MeltBolt11Request {
}
}

// TODO: to be deprecated
/// Melt Response [NUT-05]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MeltBolt11Response {
/// Indicate if payment was successful
pub paid: bool,
/// Bolt11 preimage
pub payment_preimage: Option<String>,
/// Change
pub change: Option<Vec<BlindSignature>>,
}

impl From<MeltQuoteBolt11Response> for MeltBolt11Response {
fn from(quote_response: MeltQuoteBolt11Response) -> MeltBolt11Response {
MeltBolt11Response {
paid: quote_response.paid.unwrap(),
payment_preimage: quote_response.payment_preimage,
change: quote_response.change,
}
}
}

/// Melt Method Settings
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct MeltMethodSettings {
Expand Down
7 changes: 3 additions & 4 deletions crates/cdk/src/wallet/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use url::Url;

use super::Error;
use crate::error::ErrorResponse;
use crate::nuts::nut05::MeltBolt11Response;
use crate::nuts::nut15::Mpp;
use crate::nuts::{
BlindedMessage, CheckStateRequest, CheckStateResponse, CurrencyUnit, Id, KeySet, KeysResponse,
Expand Down Expand Up @@ -267,7 +266,7 @@ impl HttpClient {
quote: String,
inputs: Vec<Proof>,
outputs: Option<Vec<BlindedMessage>>,
) -> Result<MeltBolt11Response, Error> {
) -> Result<MeltQuoteBolt11Response, Error> {
let url = join_url(mint_url, &["v1", "melt", "bolt11"])?;

let request = MeltBolt11Request {
Expand All @@ -286,9 +285,9 @@ impl HttpClient {
.await?;

match serde_json::from_value::<MeltQuoteBolt11Response>(res.clone()) {
Ok(melt_quote_response) => Ok(melt_quote_response.into()),
Ok(melt_quote_response) => Ok(melt_quote_response),
Err(_) => {
if let Ok(res) = serde_json::from_value::<MeltBolt11Response>(res.clone()) {
if let Ok(res) = serde_json::from_value::<MeltQuoteBolt11Response>(res.clone()) {
return Ok(res);
}
Err(ErrorResponse::from_value(res)?.into())
Expand Down
12 changes: 2 additions & 10 deletions crates/cdk/src/wallet/melt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ use tracing::instrument;

use crate::{
dhke::construct_proofs,
nuts::{
CurrencyUnit, MeltQuoteBolt11Response, MeltQuoteState, PreMintSecrets, Proofs, PublicKey,
State,
},
nuts::{CurrencyUnit, MeltQuoteBolt11Response, PreMintSecrets, Proofs, PublicKey, State},
types::{Melted, ProofInfo},
util::unix_time,
Amount, Error, Wallet,
Expand Down Expand Up @@ -204,13 +201,8 @@ impl Wallet {
None => None,
};

let state = match melt_response.paid {
true => MeltQuoteState::Paid,
false => MeltQuoteState::Unpaid,
};

let melted = Melted::from_proofs(
state,
melt_response.state,
melt_response.payment_preimage,
quote_info.amount,
proofs.clone(),
Expand Down

0 comments on commit 27eed93

Please sign in to comment.