fix: bolt12 ws on mint (#972)

* fix: bolt12 ws on mint

* fix: bolt12 ws on mint
This commit is contained in:
thesimplekid
2025-08-18 14:46:18 +01:00
committed by GitHub
parent f8d58e419f
commit 22926f8b21
4 changed files with 87 additions and 9 deletions

View File

@@ -433,8 +433,22 @@ impl Mint {
)
.await?;
self.pubsub_manager
.mint_quote_bolt11_status(mint_quote.clone(), MintQuoteState::Paid);
match mint_quote.payment_method {
PaymentMethod::Bolt11 => {
self.pubsub_manager
.mint_quote_bolt11_status(mint_quote.clone(), MintQuoteState::Paid);
}
PaymentMethod::Bolt12 => {
self.pubsub_manager.mint_quote_bolt12_status(
mint_quote.clone(),
wait_payment_response.payment_amount,
Amount::ZERO,
);
}
_ => {
// We don't send ws updates for unknown methods
}
}
}
} else {
tracing::info!("Received payment notification for already seen payment.");
@@ -603,8 +617,22 @@ impl Mint {
tx.commit().await?;
self.pubsub_manager
.mint_quote_bolt11_status(mint_quote, MintQuoteState::Issued);
match mint_quote.payment_method {
PaymentMethod::Bolt11 => {
self.pubsub_manager
.mint_quote_bolt11_status(mint_quote.clone(), MintQuoteState::Issued);
}
PaymentMethod::Bolt12 => {
self.pubsub_manager.mint_quote_bolt12_status(
mint_quote.clone(),
Amount::ZERO,
mint_request.total_amount()?,
);
}
PaymentMethod::Custom(_) => {
// We don't send ws updates for unknown methods
}
}
Ok(MintResponse {
signatures: blind_signatures,

View File

@@ -2,7 +2,7 @@ use cdk_common::amount::to_unit;
use cdk_common::common::PaymentProcessorKey;
use cdk_common::mint::MintQuote;
use cdk_common::util::unix_time;
use cdk_common::{MintQuoteState, PaymentMethod};
use cdk_common::{Amount, MintQuoteState, PaymentMethod};
use tracing::instrument;
use super::Mint;
@@ -39,6 +39,10 @@ impl Mint {
.check_incoming_payment_status(&quote.request_lookup_id)
.await?;
if ln_status.is_empty() {
return Ok(());
}
let mut tx = self.localstore.begin_transaction().await?;
for payment in ln_status {
@@ -52,8 +56,22 @@ impl Mint {
tx.increment_mint_quote_amount_paid(&quote.id, amount_paid, payment.payment_id)
.await?;
self.pubsub_manager
.mint_quote_bolt11_status(quote.clone(), MintQuoteState::Paid);
match quote.payment_method {
PaymentMethod::Bolt11 => {
self.pubsub_manager
.mint_quote_bolt11_status(quote.clone(), MintQuoteState::Paid);
}
PaymentMethod::Bolt12 => {
self.pubsub_manager.mint_quote_bolt12_status(
quote.clone(),
amount_paid,
Amount::ZERO,
);
}
PaymentMethod::Custom(_) => {
// We don't send ws updates for unknown methods
}
}
}
}

View File

@@ -571,7 +571,22 @@ impl Mint {
)
.await?;
pubsub_manager.mint_quote_bolt11_status(mint_quote.clone(), MintQuoteState::Paid);
match mint_quote.payment_method {
PaymentMethod::Bolt11 => {
pubsub_manager
.mint_quote_bolt11_status(mint_quote.clone(), MintQuoteState::Paid);
}
PaymentMethod::Bolt12 => {
pubsub_manager.mint_quote_bolt12_status(
mint_quote.clone(),
wait_payment_response.payment_amount,
Amount::ZERO,
);
}
_ => {
// We don't send ws updates for unknown methods
}
}
}
} else {
tracing::info!("Received payment notification for already seen payment.");

View File

@@ -4,7 +4,7 @@ use std::sync::Arc;
use cdk_common::database::{self, MintDatabase};
use cdk_common::nut17::Notification;
use cdk_common::NotificationPayload;
use cdk_common::{Amount, MintQuoteBolt12Response, NotificationPayload};
use uuid::Uuid;
use super::OnSubscription;
@@ -60,6 +60,23 @@ impl PubSubManager {
self.broadcast(event.into());
}
/// Helper function to emit a MintQuoteBolt11Response status
pub fn mint_quote_bolt12_status<E: TryInto<MintQuoteBolt12Response<Uuid>>>(
&self,
quote: E,
amount_paid: Amount,
amount_issued: Amount,
) {
if let Ok(mut event) = quote.try_into() {
event.amount_paid += amount_paid;
event.amount_issued += amount_issued;
self.broadcast(event.into());
} else {
tracing::warn!("Could not convert quote to MintQuoteResponse");
}
}
/// Helper function to emit a MeltQuoteBolt11Response status
pub fn melt_quote_status<E: Into<MeltQuoteBolt11Response<Uuid>>>(
&self,