reth_trie/hashed_cursor/
noop.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use super::{HashedCursor, HashedCursorFactory, HashedStorageCursor};
use alloy_primitives::{B256, U256};
use reth_primitives::Account;
use reth_storage_errors::db::DatabaseError;

/// Noop hashed cursor factory.
#[derive(Default, Debug)]
#[non_exhaustive]
pub struct NoopHashedCursorFactory;

impl HashedCursorFactory for NoopHashedCursorFactory {
    type AccountCursor = NoopHashedAccountCursor;
    type StorageCursor = NoopHashedStorageCursor;

    fn hashed_account_cursor(&self) -> Result<Self::AccountCursor, DatabaseError> {
        Ok(NoopHashedAccountCursor::default())
    }

    fn hashed_storage_cursor(
        &self,
        _hashed_address: B256,
    ) -> Result<Self::StorageCursor, DatabaseError> {
        Ok(NoopHashedStorageCursor::default())
    }
}

/// Noop account hashed cursor.
#[derive(Default, Debug)]
#[non_exhaustive]
pub struct NoopHashedAccountCursor;

impl HashedCursor for NoopHashedAccountCursor {
    type Value = Account;

    fn seek(&mut self, _key: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
        Ok(None)
    }

    fn next(&mut self) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
        Ok(None)
    }
}

/// Noop account hashed cursor.
#[derive(Default, Debug)]
#[non_exhaustive]
pub struct NoopHashedStorageCursor;

impl HashedCursor for NoopHashedStorageCursor {
    type Value = U256;

    fn seek(&mut self, _key: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
        Ok(None)
    }

    fn next(&mut self) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
        Ok(None)
    }
}

impl HashedStorageCursor for NoopHashedStorageCursor {
    fn is_storage_empty(&mut self) -> Result<bool, DatabaseError> {
        Ok(true)
    }
}