Skip to content

Commit

Permalink
Skip expired invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Apr 4, 2024
1 parent 949155e commit 19ad32a
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 19ad32a

Please sign in to comment.