reth_storage_api/
block_hash.rs

1use alloy_eips::BlockHashOrNumber;
2use alloy_primitives::{BlockNumber, B256};
3use reth_storage_errors::provider::ProviderResult;
4
5/// Client trait for fetching block hashes by number.
6#[auto_impl::auto_impl(&, Arc, Box)]
7pub trait BlockHashReader: Send + Sync {
8    /// Get the hash of the block with the given number. Returns `None` if no block with this number
9    /// exists.
10    fn block_hash(&self, number: BlockNumber) -> ProviderResult<Option<B256>>;
11
12    /// Get the hash of the block with the given number. Returns `None` if no block with this number
13    /// exists.
14    fn convert_block_hash(
15        &self,
16        hash_or_number: BlockHashOrNumber,
17    ) -> ProviderResult<Option<B256>> {
18        match hash_or_number {
19            BlockHashOrNumber::Hash(hash) => Ok(Some(hash)),
20            BlockHashOrNumber::Number(num) => self.block_hash(num),
21        }
22    }
23
24    /// Get headers in range of block hashes or numbers
25    ///
26    /// Returns the available hashes of that range.
27    ///
28    /// Note: The range is `start..end`, so the expected result is `[start..end)`
29    fn canonical_hashes_range(
30        &self,
31        start: BlockNumber,
32        end: BlockNumber,
33    ) -> ProviderResult<Vec<B256>>;
34}