Skip to content

Commit

Permalink
feat: add remove to account tx index (#317)
Browse files Browse the repository at this point in the history
Subsequent PRs will integrate this remove into the tx_pool

commit-id:ef407f33

Co-authored-by: Gilad Chase <[email protected]>
  • Loading branch information
giladchase and Gilad Chase authored Jun 30, 2024
1 parent 19d8527 commit acd65d5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/mempool/src/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,17 @@ impl AccountTransactionIndex {
pub fn insert(&mut self, tx: TransactionReference) -> Option<TransactionReference> {
self.0.entry(tx.sender_address).or_default().insert(tx.nonce, tx)
}

pub fn remove(&mut self, tx: TransactionReference) -> Option<TransactionReference> {
let ThinTransaction { sender_address, nonce, .. } = tx.0;
let account_txs = self.0.get_mut(&sender_address)?;

let removed_tx = account_txs.remove(&nonce);

if removed_tx.is_some() && account_txs.is_empty() {
self.0.remove(&sender_address);
}

removed_tx
}
}

0 comments on commit acd65d5

Please sign in to comment.