Change invoice status to "timeout" after 30 minutes of inactivity
This commit is contained in:
parent
b0e79e26a4
commit
383fc13059
2 changed files with 14 additions and 0 deletions
|
@ -13,6 +13,7 @@ pub enum InvoiceStatus {
|
|||
Open,
|
||||
Paid,
|
||||
Forwarded,
|
||||
Timeout,
|
||||
}
|
||||
|
||||
impl From<&InvoiceStatus> for i16 {
|
||||
|
@ -21,6 +22,7 @@ impl From<&InvoiceStatus> for i16 {
|
|||
InvoiceStatus::Open => 1,
|
||||
InvoiceStatus::Paid => 2,
|
||||
InvoiceStatus::Forwarded => 3,
|
||||
InvoiceStatus::Timeout => 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +35,7 @@ impl TryFrom<i16> for InvoiceStatus {
|
|||
1 => Self::Open,
|
||||
2 => Self::Paid,
|
||||
3 => Self::Forwarded,
|
||||
4 => Self::Timeout,
|
||||
_ => return Err(ConversionError),
|
||||
};
|
||||
Ok(invoice_status)
|
||||
|
|
|
@ -27,6 +27,8 @@ use crate::models::{
|
|||
};
|
||||
use super::wallet::{send_monero, DEFAULT_ACCOUNT, MoneroError};
|
||||
|
||||
const INVOICE_TIMEOUT: i64 = 30 * 60; // 30 minutes
|
||||
|
||||
pub async fn check_monero_subscriptions(
|
||||
instance: &Instance,
|
||||
config: &MoneroConfig,
|
||||
|
@ -48,6 +50,15 @@ pub async fn check_monero_subscriptions(
|
|||
InvoiceStatus::Open,
|
||||
).await?;
|
||||
for invoice in open_invoices {
|
||||
let invoice_age = Utc::now() - invoice.created_at;
|
||||
if invoice_age.num_seconds() >= INVOICE_TIMEOUT {
|
||||
set_invoice_status(
|
||||
db_client,
|
||||
&invoice.id,
|
||||
InvoiceStatus::Timeout,
|
||||
).await?;
|
||||
continue;
|
||||
};
|
||||
let address = Address::from_str(&invoice.payment_address)?;
|
||||
let address_index = wallet_client.get_address_index(address).await?;
|
||||
address_waitlist.push(address_index.minor);
|
||||
|
|
Loading…
Reference in a new issue