mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-09 07:55:53 +01:00
Merge pull request #989 from crodas/bug/bolt12-missing-notifications
Fixed bolt12 missing payments notifications
This commit is contained in:
@@ -440,29 +440,16 @@ impl Mint {
|
||||
payment_amount_quote_unit
|
||||
);
|
||||
|
||||
tx.increment_mint_quote_amount_paid(
|
||||
&mint_quote.id,
|
||||
payment_amount_quote_unit,
|
||||
wait_payment_response.payment_id,
|
||||
)
|
||||
.await?;
|
||||
let total_paid = tx
|
||||
.increment_mint_quote_amount_paid(
|
||||
&mint_quote.id,
|
||||
payment_amount_quote_unit,
|
||||
wait_payment_response.payment_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
self.pubsub_manager
|
||||
.mint_quote_payment(mint_quote, total_paid);
|
||||
}
|
||||
} else {
|
||||
tracing::info!("Received payment notification for already seen payment.");
|
||||
@@ -626,27 +613,16 @@ impl Mint {
|
||||
)
|
||||
.await?;
|
||||
|
||||
tx.increment_mint_quote_amount_issued(&mint_request.quote, mint_request.total_amount()?)
|
||||
let amount_issued = mint_request.total_amount()?;
|
||||
|
||||
let total_issued = tx
|
||||
.increment_mint_quote_amount_issued(&mint_request.quote, amount_issued)
|
||||
.await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
self.pubsub_manager
|
||||
.mint_quote_issue(&mint_quote, total_issued);
|
||||
|
||||
Ok(MintResponse {
|
||||
signatures: blind_signatures,
|
||||
|
||||
@@ -61,25 +61,11 @@ impl Mint {
|
||||
quote.increment_amount_paid(amount_paid)?;
|
||||
quote.add_payment(amount_paid, payment.payment_id.clone(), unix_time())?;
|
||||
|
||||
tx.increment_mint_quote_amount_paid("e.id, amount_paid, payment.payment_id)
|
||||
let total_paid = tx
|
||||
.increment_mint_quote_amount_paid("e.id, amount_paid, payment.payment_id)
|
||||
.await?;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
self.pubsub_manager.mint_quote_payment(quote, total_paid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -573,29 +573,14 @@ impl Mint {
|
||||
payment_amount_quote_unit
|
||||
);
|
||||
|
||||
tx.increment_mint_quote_amount_paid(
|
||||
&mint_quote.id,
|
||||
payment_amount_quote_unit,
|
||||
wait_payment_response.payment_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
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(),
|
||||
payment_amount_quote_unit,
|
||||
Amount::ZERO,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
// We don't send ws updates for unknown methods
|
||||
}
|
||||
}
|
||||
let total_paid = tx
|
||||
.increment_mint_quote_amount_paid(
|
||||
&mint_quote.id,
|
||||
payment_amount_quote_unit,
|
||||
wait_payment_response.payment_id,
|
||||
)
|
||||
.await?;
|
||||
pubsub_manager.mint_quote_payment(mint_quote, total_paid);
|
||||
}
|
||||
} else {
|
||||
tracing::info!("Received payment notification for already seen payment.");
|
||||
@@ -752,9 +737,13 @@ impl Mint {
|
||||
|
||||
let amount = melt_quote.amount;
|
||||
|
||||
tx.increment_mint_quote_amount_paid(&mint_quote.id, amount, melt_quote.id.to_string())
|
||||
let total_paid = tx
|
||||
.increment_mint_quote_amount_paid(&mint_quote.id, amount, melt_quote.id.to_string())
|
||||
.await?;
|
||||
|
||||
self.pubsub_manager
|
||||
.mint_quote_payment(&mint_quote, total_paid);
|
||||
|
||||
tracing::info!(
|
||||
"Melt quote {} paid Mint quote {}",
|
||||
melt_quote.id,
|
||||
|
||||
@@ -3,8 +3,9 @@ use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
||||
use cdk_common::database::{self, MintDatabase};
|
||||
use cdk_common::mint::MintQuote;
|
||||
use cdk_common::nut17::Notification;
|
||||
use cdk_common::{Amount, MintQuoteBolt12Response, NotificationPayload};
|
||||
use cdk_common::{Amount, MintQuoteBolt12Response, NotificationPayload, PaymentMethod};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::OnSubscription;
|
||||
@@ -48,6 +49,44 @@ impl PubSubManager {
|
||||
self.broadcast(event.into().into());
|
||||
}
|
||||
|
||||
/// Helper function to publish even of a mint quote being paid
|
||||
pub fn mint_quote_issue(&self, mint_quote: &MintQuote, total_issued: Amount) {
|
||||
match mint_quote.payment_method {
|
||||
PaymentMethod::Bolt11 => {
|
||||
self.mint_quote_bolt11_status(mint_quote.clone(), MintQuoteState::Issued);
|
||||
}
|
||||
PaymentMethod::Bolt12 => {
|
||||
self.mint_quote_bolt12_status(
|
||||
mint_quote.clone(),
|
||||
mint_quote.amount_paid(),
|
||||
total_issued,
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
// We don't send ws updates for unknown methods
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to publish even of a mint quote being paid
|
||||
pub fn mint_quote_payment(&self, mint_quote: &MintQuote, total_paid: Amount) {
|
||||
match mint_quote.payment_method {
|
||||
PaymentMethod::Bolt11 => {
|
||||
self.mint_quote_bolt11_status(mint_quote.clone(), MintQuoteState::Paid);
|
||||
}
|
||||
PaymentMethod::Bolt12 => {
|
||||
self.mint_quote_bolt12_status(
|
||||
mint_quote.clone(),
|
||||
total_paid,
|
||||
mint_quote.amount_issued(),
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
// We don't send ws updates for unknown methods
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to emit a MintQuoteBolt11Response status
|
||||
pub fn mint_quote_bolt11_status<E: Into<MintQuoteBolt11Response<Uuid>>>(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user