example_database_components/
block_hash.rs1use auto_impl::auto_impl;
4use core::{error::Error as StdError, ops::Deref};
5use revm::primitives::B256;
6use std::sync::Arc;
7
8#[auto_impl(&mut, Box)]
12pub trait BlockHash {
13 type Error: StdError;
15
16 fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error>;
18}
19
20#[auto_impl(&, &mut, Box, Rc, Arc)]
24pub trait BlockHashRef {
25 type Error: StdError;
27
28 fn block_hash(&self, number: u64) -> Result<B256, Self::Error>;
30}
31
32impl<T> BlockHash for &T
33where
34 T: BlockHashRef,
35{
36 type Error = <T as BlockHashRef>::Error;
37
38 fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
39 BlockHashRef::block_hash(*self, number)
40 }
41}
42
43impl<T> BlockHash for Arc<T>
44where
45 T: BlockHashRef,
46{
47 type Error = <T as BlockHashRef>::Error;
48
49 fn block_hash(&mut self, number: u64) -> Result<B256, Self::Error> {
50 self.deref().block_hash(number)
51 }
52}