reth_storage_api/
block_hash.rs

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