Skip to content

Commit 9bb7cfb

Browse files
authored
feat: add check for custom mint and melt quote (#1550)
1 parent 21ec7b8 commit 9bb7cfb

3 files changed

Lines changed: 92 additions & 7 deletions

File tree

crates/cdk-integration-tests/src/init_pure_tests.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use bip39::Mnemonic;
1111
use cashu::nut00::KnownMethod;
1212
use cashu::quote_id::QuoteId;
1313
use cashu::{
14-
MeltQuoteBolt12Request, MeltQuoteCustomRequest, MintQuoteBolt12Request,
15-
MintQuoteBolt12Response, MintQuoteCustomRequest, MintQuoteCustomResponse,
14+
MeltQuoteBolt12Request, MeltQuoteCustomRequest, MeltQuoteCustomResponse,
15+
MintQuoteBolt12Request, MintQuoteBolt12Response, MintQuoteCustomRequest,
16+
MintQuoteCustomResponse,
1617
};
1718
use cdk::amount::SplitTarget;
1819
use cdk::cdk_database::{self, WalletDatabase};
@@ -231,11 +232,31 @@ impl MintConnector for DirectMintConnection {
231232
Err(Error::UnsupportedPaymentMethod)
232233
}
233234

235+
/// Mint Quote Status for Custom Payment Method
236+
async fn get_mint_quote_custom_status(
237+
&self,
238+
_method: &str,
239+
_quote_id: &str,
240+
) -> Result<MintQuoteCustomResponse<String>, Error> {
241+
// Custom payment methods not implemented in test mock
242+
Err(Error::UnsupportedPaymentMethod)
243+
}
244+
234245
/// Melt Quote for Custom Payment Method
235246
async fn post_melt_custom_quote(
236247
&self,
237248
_request: MeltQuoteCustomRequest,
238-
) -> Result<MeltQuoteBolt11Response<String>, Error> {
249+
) -> Result<MeltQuoteCustomResponse<String>, Error> {
250+
// Custom payment methods not implemented in test mock
251+
Err(Error::UnsupportedPaymentMethod)
252+
}
253+
254+
/// Melt Quote Status for Custom Payment Method
255+
async fn get_melt_quote_custom_status(
256+
&self,
257+
_method: &str,
258+
_quote_id: &str,
259+
) -> Result<MeltQuoteCustomResponse<String>, Error> {
239260
// Custom payment methods not implemented in test mock
240261
Err(Error::UnsupportedPaymentMethod)
241262
}

crates/cdk/src/wallet/mint_connector/http_client.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use std::collections::HashSet;
33
use std::sync::{Arc, RwLock as StdRwLock};
44

55
use async_trait::async_trait;
6-
use cdk_common::{nut19, MeltQuoteBolt12Request, MintQuoteBolt12Request, MintQuoteBolt12Response};
6+
use cdk_common::{
7+
nut19, MeltQuoteBolt12Request, MeltQuoteCustomResponse, MintQuoteBolt12Request,
8+
MintQuoteBolt12Response,
9+
};
710
#[cfg(feature = "auth")]
811
use cdk_common::{Method, ProtectedEndpoint, RoutePath};
912
use serde::de::DeserializeOwned;
@@ -622,12 +625,34 @@ where
622625
self.transport.http_post(url, auth_token, &request).await
623626
}
624627

628+
/// Mint Quote Status for Custom Payment Method
629+
#[instrument(skip(self), fields(mint_url = %self.mint_url))]
630+
async fn get_mint_quote_custom_status(
631+
&self,
632+
method: &str,
633+
quote_id: &str,
634+
) -> Result<MintQuoteCustomResponse<String>, Error> {
635+
let url = self
636+
.mint_url
637+
.join_paths(&["v1", "mint", "quote", method, quote_id])?;
638+
639+
#[cfg(feature = "auth")]
640+
let auth_token = self
641+
.get_auth_token(Method::Get, RoutePath::MintQuote(method.to_string()))
642+
.await?;
643+
644+
#[cfg(not(feature = "auth"))]
645+
let auth_token = None;
646+
647+
self.transport.http_get(url, auth_token).await
648+
}
649+
625650
/// Melt Quote for Custom Payment Method
626651
#[instrument(skip(self, request), fields(mint_url = %self.mint_url))]
627652
async fn post_melt_custom_quote(
628653
&self,
629654
request: MeltQuoteCustomRequest,
630-
) -> Result<MeltQuoteBolt11Response<String>, Error> {
655+
) -> Result<MeltQuoteCustomResponse<String>, Error> {
631656
let url = self
632657
.mint_url
633658
.join_paths(&["v1", "melt", "quote", &request.method])?;
@@ -642,6 +667,28 @@ where
642667

643668
self.transport.http_post(url, auth_token, &request).await
644669
}
670+
671+
/// Melt Quote Status for Custom Payment Method
672+
#[instrument(skip(self), fields(mint_url = %self.mint_url))]
673+
async fn get_melt_quote_custom_status(
674+
&self,
675+
method: &str,
676+
quote_id: &str,
677+
) -> Result<MeltQuoteCustomResponse<String>, Error> {
678+
let url = self
679+
.mint_url
680+
.join_paths(&["v1", "melt", "quote", method, quote_id])?;
681+
682+
#[cfg(feature = "auth")]
683+
let auth_token = self
684+
.get_auth_token(Method::Get, RoutePath::MeltQuote(method.to_string()))
685+
.await?;
686+
687+
#[cfg(not(feature = "auth"))]
688+
let auth_token = None;
689+
690+
self.transport.http_get(url, auth_token).await
691+
}
645692
}
646693

647694
/// Http Client

crates/cdk/src/wallet/mint_connector/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
use std::fmt::Debug;
44

55
use async_trait::async_trait;
6-
use cdk_common::{MeltQuoteBolt12Request, MintQuoteBolt12Request, MintQuoteBolt12Response};
6+
use cdk_common::{
7+
MeltQuoteBolt12Request, MeltQuoteCustomResponse, MintQuoteBolt12Request,
8+
MintQuoteBolt12Response,
9+
};
710

811
use super::Error;
912
// Re-export Lightning address types for trait implementers
@@ -139,9 +142,23 @@ pub trait MintConnector: Debug {
139142
request: MintQuoteCustomRequest,
140143
) -> Result<MintQuoteCustomResponse<String>, Error>;
141144

145+
/// Mint Quote Status for Custom Payment Method
146+
async fn get_mint_quote_custom_status(
147+
&self,
148+
method: &str,
149+
quote_id: &str,
150+
) -> Result<MintQuoteCustomResponse<String>, Error>;
151+
142152
/// Melt Quote for Custom Payment Method
143153
async fn post_melt_custom_quote(
144154
&self,
145155
request: MeltQuoteCustomRequest,
146-
) -> Result<MeltQuoteBolt11Response<String>, Error>;
156+
) -> Result<MeltQuoteCustomResponse<String>, Error>;
157+
158+
/// Melt Quote Status for Custom Payment Method
159+
async fn get_melt_quote_custom_status(
160+
&self,
161+
method: &str,
162+
quote_id: &str,
163+
) -> Result<MeltQuoteCustomResponse<String>, Error>;
147164
}

0 commit comments

Comments
 (0)