cuprated/txpool/
txs_being_handled.rs1use std::sync::Arc;
2
3use dashmap::DashSet;
4
5#[derive(Clone)]
7pub struct TxsBeingHandled(Arc<DashSet<[u8; 32]>>);
8
9impl TxsBeingHandled {
10 pub fn new() -> Self {
12 Self(Arc::new(DashSet::new()))
13 }
14
15 pub fn local_tracker(&self) -> TxsBeingHandledLocally {
17 TxsBeingHandledLocally {
18 txs_being_handled: self.clone(),
19 txs: vec![],
20 }
21 }
22}
23
24pub struct TxsBeingHandledLocally {
29 txs_being_handled: TxsBeingHandled,
30 txs: Vec<[u8; 32]>,
31}
32
33impl TxsBeingHandledLocally {
34 pub fn try_add_tx(&mut self, tx_blob_hash: [u8; 32]) -> bool {
38 if !self.txs_being_handled.0.insert(tx_blob_hash) {
39 return false;
40 }
41
42 self.txs.push(tx_blob_hash);
43 true
44 }
45}
46
47impl Drop for TxsBeingHandledLocally {
48 fn drop(&mut self) {
49 for hash in &self.txs {
50 self.txs_being_handled.0.remove(hash);
51 }
52 }
53}