Skip to content

Commit

Permalink
Merge pull request #16 from MutinyWallet/skip-expired-invoices
Browse files Browse the repository at this point in the history
Skip expired invoices
  • Loading branch information
TonyGiorgio authored Apr 8, 2024
2 parents 386a7a5 + 19ad32a commit 3d54d03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ pub(crate) async fn handle_pending_invoices(state: &State) -> Result<()> {
if let Some(client) = state.mm.get_federation_client(federation_id).await {
let ln = client.get_first_module::<LightningClientModule>();
for invoice in invoices {
// Check if invoice has expired
if invoice.bolt11().is_expired() {
state
.db
.set_invoice_state(invoice, InvoiceState::Cancelled as i32)?;
continue;
}

// Create subscription to operation if it exists
if let Ok(subscription) = ln
.subscribe_ln_receive(invoice.op_id.parse().expect("invalid op_id"))
Expand Down
6 changes: 6 additions & 0 deletions src/models/invoice.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::str::FromStr;
use crate::models::schema::invoice;
use diesel::prelude::*;
use fedimint_ln_common::lightning_invoice::Bolt11Invoice;
use serde::{Deserialize, Serialize};

#[derive(
Expand All @@ -20,6 +22,10 @@ pub struct Invoice {
}

impl Invoice {
pub fn bolt11(&self) -> Bolt11Invoice {
Bolt11Invoice::from_str(&self.bolt11).expect("invalid bolt11")
}

pub fn get_invoices(conn: &mut PgConnection) -> anyhow::Result<Vec<Invoice>> {
Ok(invoice::table.load::<Self>(conn)?)
}
Expand Down

0 comments on commit 3d54d03

Please sign in to comment.