Skip to content

Commit

Permalink
Merge pull request #12 from starkbamse/invoice-removal
Browse files Browse the repository at this point in the history
Update invoice removal
  • Loading branch information
saefstroem authored May 21, 2024
2 parents 04fa698 + fbb5472 commit 26dd72b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/web3/poller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ pub async fn poll_payments(gateway: PaymentGateway) {
gateway.invoices.remove(&key);
continue;
}

if invoice.paid_at_timestamp > 0 {
// Skip the invoice if it has already been paid
continue;
}

// Check if the invoice was paid
let check_result =
check_and_process(gateway.config.provider.clone(), &invoice).await;
Expand All @@ -94,11 +100,12 @@ pub async fn poll_payments(gateway: PaymentGateway) {
);
}
}

// If the transfer_to_treasury invoice was paid, delete it, stand in queue for the
// lock to the callback function.
gateway.invoices.remove(&key);
// Set the invoice as paid so that it will not be ran again
invoice.paid_at_timestamp = get_unix_time_seconds();

// Update the invoice in the hashmap
gateway.invoices.insert(key.clone(), invoice.clone());

match gateway.config.reflector {
Sender(ref sender) => {
// Attempt to send the PriceData through the channel.
Expand Down

0 comments on commit 26dd72b

Please sign in to comment.