Browse Source

feat: remove paid field

thesimplekid 4 months ago
parent
commit
4fdc4f49d2
2 changed files with 2 additions and 77 deletions
  1. 0 3
      crates/cdk/src/mint/mint_nut04.rs
  2. 2 74
      crates/cdk/src/nuts/nut04.rs

+ 0 - 3
crates/cdk/src/mint/mint_nut04.rs

@@ -126,8 +126,6 @@ impl Mint {
             .await?
             .await?
             .ok_or(Error::UnknownQuote)?;
             .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
         // 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
         // response. In practice the wallet should not be checking the state of
         // a quote while waiting for the mint response.
         // a quote while waiting for the mint response.
@@ -139,7 +137,6 @@ impl Mint {
         Ok(MintQuoteBolt11Response {
         Ok(MintQuoteBolt11Response {
             quote: quote.id,
             quote: quote.id,
             request: quote.request,
             request: quote.request,
-            paid: Some(paid),
             state,
             state,
             expiry: Some(quote.expiry),
             expiry: Some(quote.expiry),
         })
         })

+ 2 - 74
crates/cdk/src/nuts/nut04.rs

@@ -5,8 +5,7 @@
 use std::fmt;
 use std::fmt;
 use std::str::FromStr;
 use std::str::FromStr;
 
 
-use serde::{Deserialize, Deserializer, Serialize};
-use serde_json::Value;
+use serde::{Deserialize, Serialize};
 use thiserror::Error;
 use thiserror::Error;
 
 
 use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod};
 use super::nut00::{BlindSignature, BlindedMessage, CurrencyUnit, PaymentMethod};
@@ -80,96 +79,25 @@ impl FromStr for QuoteState {
 }
 }
 
 
 /// Mint quote response [NUT-04]
 /// 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))]
 #[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
 pub struct MintQuoteBolt11Response {
 pub struct MintQuoteBolt11Response {
     /// Quote Id
     /// Quote Id
     pub quote: String,
     pub quote: String,
     /// Payment request to fulfil
     /// Payment request to fulfil
     pub request: String,
     pub request: String,
-    // TODO: To be deprecated
-    /// Whether the the request haas be paid
-    /// Deprecated
-    pub paid: Option<bool>,
     /// Quote State
     /// Quote State
     pub state: MintQuoteState,
     pub state: MintQuoteState,
     /// Unix timestamp until the quote is valid
     /// Unix timestamp until the quote is valid
     pub expiry: Option<u64>,
     pub expiry: Option<u64>,
 }
 }
 
 
-// A custom deserializer is needed until all mints
-// update some will return without the required state.
-impl<'de> Deserialize<'de> for MintQuoteBolt11Response {
-    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
-    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<bool> = value.get("paid").and_then(|p| p.as_bool());
-
-        let state: Option<String> = 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")]
 #[cfg(feature = "mint")]
 impl From<crate::mint::MintQuote> for MintQuoteBolt11Response {
 impl From<crate::mint::MintQuote> for MintQuoteBolt11Response {
     fn from(mint_quote: crate::mint::MintQuote) -> MintQuoteBolt11Response {
     fn from(mint_quote: crate::mint::MintQuote) -> MintQuoteBolt11Response {
-        let paid = mint_quote.state == QuoteState::Paid;
         MintQuoteBolt11Response {
         MintQuoteBolt11Response {
             quote: mint_quote.id,
             quote: mint_quote.id,
             request: mint_quote.request,
             request: mint_quote.request,
-            paid: Some(paid),
             state: mint_quote.state,
             state: mint_quote.state,
             expiry: Some(mint_quote.expiry),
             expiry: Some(mint_quote.expiry),
         }
         }