reth_provider/providers/state/
macros.rs

1//! Helper macros for implementing traits for various [`StateProvider`](crate::StateProvider)
2//! implementations
3
4/// A macro that delegates trait implementations to the `as_ref` function of the type.
5///
6/// Used to implement provider traits.
7macro_rules! delegate_impls_to_as_ref {
8    (for $target:ty => $($trait:ident $(where [$($generics:tt)*])? {  $(fn $func:ident$(<$($generic_arg:ident: $generic_arg_ty:path),*>)?(&self, $($arg:ident: $argty:ty),*) -> $ret:path;)* })* ) => {
9
10        $(
11          impl<'a, $($($generics)*)?> $trait for $target {
12              $(
13                  fn $func$(<$($generic_arg: $generic_arg_ty),*>)?(&self, $($arg: $argty),*) -> $ret {
14                    self.as_ref().$func($($arg),*)
15                  }
16              )*
17          }
18        )*
19    };
20}
21
22pub(crate) use delegate_impls_to_as_ref;
23
24/// Delegates the provider trait implementations to the `as_ref` function of the type:
25///
26/// [`AccountReader`](crate::AccountReader)
27/// [`BlockHashReader`](crate::BlockHashReader)
28/// [`StateProvider`](crate::StateProvider)
29macro_rules! delegate_provider_impls {
30    ($target:ty $(where [$($generics:tt)*])?) => {
31        $crate::providers::state::macros::delegate_impls_to_as_ref!(
32            for $target =>
33            AccountReader $(where [$($generics)*])? {
34                fn basic_account(&self, address: &alloy_primitives::Address) -> reth_storage_errors::provider::ProviderResult<Option<reth_primitives::Account>>;
35            }
36            BlockHashReader $(where [$($generics)*])? {
37                fn block_hash(&self, number: u64) -> reth_storage_errors::provider::ProviderResult<Option<alloy_primitives::B256>>;
38                fn canonical_hashes_range(&self, start: alloy_primitives::BlockNumber, end: alloy_primitives::BlockNumber) -> reth_storage_errors::provider::ProviderResult<Vec<alloy_primitives::B256>>;
39            }
40            StateProvider $(where [$($generics)*])? {
41                fn storage(&self, account: alloy_primitives::Address, storage_key: alloy_primitives::StorageKey) -> reth_storage_errors::provider::ProviderResult<Option<alloy_primitives::StorageValue>>;
42                fn bytecode_by_hash(&self, code_hash: &alloy_primitives::B256) -> reth_storage_errors::provider::ProviderResult<Option<reth_primitives::Bytecode>>;
43            }
44            StateRootProvider $(where [$($generics)*])? {
45                fn state_root(&self, state: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult<alloy_primitives::B256>;
46                fn state_root_from_nodes(&self, input: reth_trie::TrieInput) -> reth_storage_errors::provider::ProviderResult<alloy_primitives::B256>;
47                fn state_root_with_updates(&self, state: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult<(alloy_primitives::B256, reth_trie::updates::TrieUpdates)>;
48                fn state_root_from_nodes_with_updates(&self, input: reth_trie::TrieInput) -> reth_storage_errors::provider::ProviderResult<(alloy_primitives::B256, reth_trie::updates::TrieUpdates)>;
49            }
50            StorageRootProvider $(where [$($generics)*])? {
51                fn storage_root(&self, address: alloy_primitives::Address, storage: reth_trie::HashedStorage) -> reth_storage_errors::provider::ProviderResult<alloy_primitives::B256>;
52                fn storage_proof(&self, address: alloy_primitives::Address, slot: alloy_primitives::B256, storage: reth_trie::HashedStorage) -> reth_storage_errors::provider::ProviderResult<reth_trie::StorageProof>;
53                fn storage_multiproof(&self, address: alloy_primitives::Address, slots: &[alloy_primitives::B256], storage: reth_trie::HashedStorage) -> reth_storage_errors::provider::ProviderResult<reth_trie::StorageMultiProof>;
54            }
55            StateProofProvider $(where [$($generics)*])? {
56                fn proof(&self, input: reth_trie::TrieInput, address: alloy_primitives::Address, slots: &[alloy_primitives::B256]) -> reth_storage_errors::provider::ProviderResult<reth_trie::AccountProof>;
57                fn multiproof(&self, input: reth_trie::TrieInput, targets: reth_trie::MultiProofTargets) -> reth_storage_errors::provider::ProviderResult<reth_trie::MultiProof>;
58                fn witness(&self, input: reth_trie::TrieInput, target: reth_trie::HashedPostState) -> reth_storage_errors::provider::ProviderResult<Vec<alloy_primitives::Bytes>>;
59            }
60            HashedPostStateProvider $(where [$($generics)*])? {
61                fn hashed_post_state(&self, bundle_state: &revm_database::BundleState) -> reth_trie::HashedPostState;
62            }
63        );
64    }
65}
66
67pub(crate) use delegate_provider_impls;