use alloy_primitives::B256;
use derive_more::{Deref, DerefMut};
use reth_trie::prefix_set::PrefixSet;
use std::collections::HashMap;
#[derive(Deref, DerefMut, Debug)]
pub struct StorageRootTargets(HashMap<B256, PrefixSet>);
impl StorageRootTargets {
pub fn new(
changed_accounts: impl IntoIterator<Item = B256>,
storage_prefix_sets: impl IntoIterator<Item = (B256, PrefixSet)>,
) -> Self {
Self(
changed_accounts
.into_iter()
.map(|address| (address, PrefixSet::default()))
.chain(storage_prefix_sets)
.collect(),
)
}
}
impl IntoIterator for StorageRootTargets {
type Item = (B256, PrefixSet);
type IntoIter = std::collections::hash_map::IntoIter<B256, PrefixSet>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
#[cfg(feature = "parallel")]
impl rayon::iter::IntoParallelIterator for StorageRootTargets {
type Iter = rayon::collections::hash_map::IntoIter<B256, PrefixSet>;
type Item = (B256, PrefixSet);
fn into_par_iter(self) -> Self::Iter {
self.0.into_par_iter()
}
}