blockchain/mod.rs: minor cleanup

This commit is contained in:
skoupidi
2024-05-03 18:58:33 +03:00
parent 5f5cfbafa8
commit 7a891b0b90

View File

@@ -271,25 +271,7 @@ impl Blockchain {
/// Remove a given slice of pending transactions from the blockchain database.
pub fn remove_pending_txs(&self, txs: &[Transaction]) -> Result<()> {
let txs_hashes: Vec<TransactionHash> = txs.iter().map(|tx| tx.hash()).collect();
let indexes = self.transactions.get_all_pending_order()?;
// We could do indexes.iter().map(|x| txs_hashes.contains(x.1)).collect.map(|x| x.0).collect
// but this is faster since we don't do the second iteration
let mut removed_indexes = vec![];
for index in indexes {
if txs_hashes.contains(&index.1) {
removed_indexes.push(index.0);
}
}
let txs_batch = self.transactions.remove_batch_pending(&txs_hashes);
let txs_order_batch = self.transactions.remove_batch_pending_order(&removed_indexes);
// Perform an atomic transaction over the trees and apply the batches.
let trees = [self.transactions.pending.clone(), self.transactions.pending_order.clone()];
let batches = [txs_batch, txs_order_batch];
self.atomic_write(&trees, &batches)?;
Ok(())
self.remove_pending_txs_hashes(&txs_hashes)
}
/// Remove a given slice of pending transactions hashes from the blockchain database.