arbos/filtered_transactions/
mod.rs1use alloy_primitives::B256;
2use revm::Database;
3
4use arb_storage::Storage;
5
6const PRESENT_HASH: B256 = {
7 let mut bytes = [0u8; 32];
8 bytes[31] = 1;
9 B256::new(bytes)
10};
11
12pub struct FilteredTransactionsState<D> {
14 store: Storage<D>,
15}
16
17impl<D: Database> FilteredTransactionsState<D> {
18 pub fn open(sto: Storage<D>) -> Self {
19 Self { store: sto }
20 }
21
22 pub fn add(&self, tx_hash: B256) -> Result<(), ()> {
23 self.store.set(tx_hash, PRESENT_HASH)
24 }
25
26 pub fn delete(&self, tx_hash: B256) -> Result<(), ()> {
27 self.store.set(tx_hash, B256::ZERO)
28 }
29
30 pub fn is_filtered(&self, tx_hash: B256) -> Result<bool, ()> {
31 let value = self.store.get(tx_hash)?;
32 Ok(value == PRESENT_HASH)
33 }
34
35 pub fn is_filtered_free(&self, tx_hash: B256) -> bool {
37 self.store
38 .get(tx_hash)
39 .map(|v| v == PRESENT_HASH)
40 .unwrap_or(false)
41 }
42
43 pub fn delete_free(&self, tx_hash: B256) {
45 let _ = self.store.set(tx_hash, B256::ZERO);
46 }
47}