Эх сурвалжийг харах

feat: add check for custom mint and melt quote (#1550)

tsk 6 өдөр өмнө
parent
commit
9bb7cfba2c

+ 24 - 3
crates/cdk-integration-tests/src/init_pure_tests.rs

@@ -11,8 +11,9 @@ use bip39::Mnemonic;
 use cashu::nut00::KnownMethod;
 use cashu::quote_id::QuoteId;
 use cashu::{
-    MeltQuoteBolt12Request, MeltQuoteCustomRequest, MintQuoteBolt12Request,
-    MintQuoteBolt12Response, MintQuoteCustomRequest, MintQuoteCustomResponse,
+    MeltQuoteBolt12Request, MeltQuoteCustomRequest, MeltQuoteCustomResponse,
+    MintQuoteBolt12Request, MintQuoteBolt12Response, MintQuoteCustomRequest,
+    MintQuoteCustomResponse,
 };
 use cdk::amount::SplitTarget;
 use cdk::cdk_database::{self, WalletDatabase};
@@ -231,11 +232,31 @@ impl MintConnector for DirectMintConnection {
         Err(Error::UnsupportedPaymentMethod)
     }
 
+    /// Mint Quote Status for Custom Payment Method
+    async fn get_mint_quote_custom_status(
+        &self,
+        _method: &str,
+        _quote_id: &str,
+    ) -> Result<MintQuoteCustomResponse<String>, Error> {
+        // Custom payment methods not implemented in test mock
+        Err(Error::UnsupportedPaymentMethod)
+    }
+
     /// Melt Quote for Custom Payment Method
     async fn post_melt_custom_quote(
         &self,
         _request: MeltQuoteCustomRequest,
-    ) -> Result<MeltQuoteBolt11Response<String>, Error> {
+    ) -> Result<MeltQuoteCustomResponse<String>, Error> {
+        // Custom payment methods not implemented in test mock
+        Err(Error::UnsupportedPaymentMethod)
+    }
+
+    /// Melt Quote Status for Custom Payment Method
+    async fn get_melt_quote_custom_status(
+        &self,
+        _method: &str,
+        _quote_id: &str,
+    ) -> Result<MeltQuoteCustomResponse<String>, Error> {
         // Custom payment methods not implemented in test mock
         Err(Error::UnsupportedPaymentMethod)
     }

+ 49 - 2
crates/cdk/src/wallet/mint_connector/http_client.rs

@@ -3,7 +3,10 @@ use std::collections::HashSet;
 use std::sync::{Arc, RwLock as StdRwLock};
 
 use async_trait::async_trait;
-use cdk_common::{nut19, MeltQuoteBolt12Request, MintQuoteBolt12Request, MintQuoteBolt12Response};
+use cdk_common::{
+    nut19, MeltQuoteBolt12Request, MeltQuoteCustomResponse, MintQuoteBolt12Request,
+    MintQuoteBolt12Response,
+};
 #[cfg(feature = "auth")]
 use cdk_common::{Method, ProtectedEndpoint, RoutePath};
 use serde::de::DeserializeOwned;
@@ -622,12 +625,34 @@ where
         self.transport.http_post(url, auth_token, &request).await
     }
 
+    /// Mint Quote Status for Custom Payment Method
+    #[instrument(skip(self), fields(mint_url = %self.mint_url))]
+    async fn get_mint_quote_custom_status(
+        &self,
+        method: &str,
+        quote_id: &str,
+    ) -> Result<MintQuoteCustomResponse<String>, Error> {
+        let url = self
+            .mint_url
+            .join_paths(&["v1", "mint", "quote", method, quote_id])?;
+
+        #[cfg(feature = "auth")]
+        let auth_token = self
+            .get_auth_token(Method::Get, RoutePath::MintQuote(method.to_string()))
+            .await?;
+
+        #[cfg(not(feature = "auth"))]
+        let auth_token = None;
+
+        self.transport.http_get(url, auth_token).await
+    }
+
     /// Melt Quote for Custom Payment Method
     #[instrument(skip(self, request), fields(mint_url = %self.mint_url))]
     async fn post_melt_custom_quote(
         &self,
         request: MeltQuoteCustomRequest,
-    ) -> Result<MeltQuoteBolt11Response<String>, Error> {
+    ) -> Result<MeltQuoteCustomResponse<String>, Error> {
         let url = self
             .mint_url
             .join_paths(&["v1", "melt", "quote", &request.method])?;
@@ -642,6 +667,28 @@ where
 
         self.transport.http_post(url, auth_token, &request).await
     }
+
+    /// Melt Quote Status for Custom Payment Method
+    #[instrument(skip(self), fields(mint_url = %self.mint_url))]
+    async fn get_melt_quote_custom_status(
+        &self,
+        method: &str,
+        quote_id: &str,
+    ) -> Result<MeltQuoteCustomResponse<String>, Error> {
+        let url = self
+            .mint_url
+            .join_paths(&["v1", "melt", "quote", method, quote_id])?;
+
+        #[cfg(feature = "auth")]
+        let auth_token = self
+            .get_auth_token(Method::Get, RoutePath::MeltQuote(method.to_string()))
+            .await?;
+
+        #[cfg(not(feature = "auth"))]
+        let auth_token = None;
+
+        self.transport.http_get(url, auth_token).await
+    }
 }
 
 /// Http Client

+ 19 - 2
crates/cdk/src/wallet/mint_connector/mod.rs

@@ -3,7 +3,10 @@
 use std::fmt::Debug;
 
 use async_trait::async_trait;
-use cdk_common::{MeltQuoteBolt12Request, MintQuoteBolt12Request, MintQuoteBolt12Response};
+use cdk_common::{
+    MeltQuoteBolt12Request, MeltQuoteCustomResponse, MintQuoteBolt12Request,
+    MintQuoteBolt12Response,
+};
 
 use super::Error;
 // Re-export Lightning address types for trait implementers
@@ -139,9 +142,23 @@ pub trait MintConnector: Debug {
         request: MintQuoteCustomRequest,
     ) -> Result<MintQuoteCustomResponse<String>, Error>;
 
+    /// Mint Quote Status for Custom Payment Method
+    async fn get_mint_quote_custom_status(
+        &self,
+        method: &str,
+        quote_id: &str,
+    ) -> Result<MintQuoteCustomResponse<String>, Error>;
+
     /// Melt Quote for Custom Payment Method
     async fn post_melt_custom_quote(
         &self,
         request: MeltQuoteCustomRequest,
-    ) -> Result<MeltQuoteBolt11Response<String>, Error>;
+    ) -> Result<MeltQuoteCustomResponse<String>, Error>;
+
+    /// Melt Quote Status for Custom Payment Method
+    async fn get_melt_quote_custom_status(
+        &self,
+        method: &str,
+        quote_id: &str,
+    ) -> Result<MeltQuoteCustomResponse<String>, Error>;
 }