From 4fdc4f49d2ed8ba74b043c163398538d4ec90352 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Tue, 29 Oct 2024 11:17:19 +0000 Subject: [PATCH] feat: remove paid field --- crates/cdk/src/mint/mint_nut04.rs | 3 -- crates/cdk/src/nuts/nut04.rs | 76 +------------------------------ 2 files changed, 2 insertions(+), 77 deletions(-) diff --git a/crates/cdk/src/mint/mint_nut04.rs b/crates/cdk/src/mint/mint_nut04.rs index 33e0c3240..91ead8baf 100644 --- a/crates/cdk/src/mint/mint_nut04.rs +++ b/crates/cdk/src/mint/mint_nut04.rs @@ -126,8 +126,6 @@ impl Mint { .await? .ok_or(Error::UnknownQuote)?; - let paid = quote.state == MintQuoteState::Paid; - // Since the pending state is not part of the NUT it should not be part of the // response. In practice the wallet should not be checking the state of // a quote while waiting for the mint response. @@ -139,7 +137,6 @@ impl Mint { Ok(MintQuoteBolt11Response { quote: quote.id, request: quote.request, - paid: Some(paid), state, expiry: Some(quote.expiry), }) diff --git a/crates/cdk/src/nuts/nut04.rs b/crates/cdk/src/nuts/nut04.rs index 3067628f6..207a7a9a3 100644 --- a/crates/cdk/src/nuts/nut04.rs +++ b/crates/cdk/src/nuts/nut04.rs @@ -5,8 +5,7 @@ use std::fmt; use std::str::FromStr; -use serde::{Deserialize, Deserializer, Serialize}; -use serde_json::Value; +use serde::{Deserialize, Serialize}; use thiserror::Error; use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod}; @@ -80,96 +79,25 @@ impl FromStr for QuoteState { } /// Mint quote response [NUT-04] -#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))] pub struct MintQuoteBolt11Response { /// Quote Id pub quote: String, /// Payment request to fulfil pub request: String, - // TODO: To be deprecated - /// Whether the the request haas be paid - /// Deprecated - pub paid: Option, /// Quote State pub state: MintQuoteState, /// Unix timestamp until the quote is valid pub expiry: Option, } -// A custom deserializer is needed until all mints -// update some will return without the required state. -impl<'de> Deserialize<'de> for MintQuoteBolt11Response { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let value = Value::deserialize(deserializer)?; - - let quote: String = serde_json::from_value( - value - .get("quote") - .ok_or(serde::de::Error::missing_field("quote"))? - .clone(), - ) - .map_err(|_| serde::de::Error::custom("Invalid quote id string"))?; - - let request: String = serde_json::from_value( - value - .get("request") - .ok_or(serde::de::Error::missing_field("request"))? - .clone(), - ) - .map_err(|_| serde::de::Error::custom("Invalid request string"))?; - - let paid: Option = value.get("paid").and_then(|p| p.as_bool()); - - let state: Option = value - .get("state") - .and_then(|s| serde_json::from_value(s.clone()).ok()); - - let (state, paid) = match (state, paid) { - (None, None) => return Err(serde::de::Error::custom("State or paid must be defined")), - (Some(state), _) => { - let state: QuoteState = QuoteState::from_str(&state) - .map_err(|_| serde::de::Error::custom("Unknown state"))?; - let paid = state == QuoteState::Paid; - - (state, paid) - } - (None, Some(paid)) => { - let state = if paid { - QuoteState::Paid - } else { - QuoteState::Unpaid - }; - (state, paid) - } - }; - - let expiry = value - .get("expiry") - .ok_or(serde::de::Error::missing_field("expiry"))? - .as_u64(); - - Ok(Self { - quote, - request, - paid: Some(paid), - state, - expiry, - }) - } -} - #[cfg(feature = "mint")] impl From for MintQuoteBolt11Response { fn from(mint_quote: crate::mint::MintQuote) -> MintQuoteBolt11Response { - let paid = mint_quote.state == QuoteState::Paid; MintQuoteBolt11Response { quote: mint_quote.id, request: mint_quote.request, - paid: Some(paid), state: mint_quote.state, expiry: Some(mint_quote.expiry), }