Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 11, 2023
1 parent 03176ec commit 6de73df
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,32 +1025,28 @@ impl Database {
}

pub async fn purge_unsent_txs(&self, relayer_id: &str) -> eyre::Result<()> {
let unsent_txs = self.get_unsent_txs().await?;

let unsent_tx_ids: Vec<_> = unsent_txs
.into_iter()
.filter(|tx| tx.relayer_id == relayer_id)
.map(|tx| tx.id)
.collect();

sqlx::query(
let (nonce,): (i64,) = sqlx::query_as(
r#"
DELETE FROM transactions
WHERE id = ANY($1::TEXT[])
UPDATE relayers
SET nonce = current_nonce
WHERE id = $1
RETURNING nonce
"#,
)
.bind(&unsent_tx_ids)
.execute(&self.pool)
.bind(relayer_id)
.fetch_one(&self.pool)
.await?;

sqlx::query(
r#"
UPDATE relayers
SET nonce = current_nonce
WHERE id = $1
DELETE FROM transactions
WHERE nonce > $1
AND id NOT IN (
SELECT tx_id FROM sent_transactions
)
"#,
)
.bind(relayer_id)
.bind(nonce)
.execute(&self.pool)
.await?;

Expand Down

0 comments on commit 6de73df

Please sign in to comment.