use primitives::{HashMap, StorageKeyMap, StorageValue};
use state::{AccountInfo, EvmStorageSlot};
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct PlainAccount {
pub info: AccountInfo,
pub storage: PlainStorage,
}
impl PlainAccount {
pub fn new_empty_with_storage(storage: PlainStorage) -> Self {
Self {
info: AccountInfo::default(),
storage,
}
}
pub fn into_components(self) -> (AccountInfo, PlainStorage) {
(self.info, self.storage)
}
}
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StorageSlot {
pub previous_or_original_value: StorageValue,
pub present_value: StorageValue,
}
impl From<EvmStorageSlot> for StorageSlot {
fn from(value: EvmStorageSlot) -> Self {
Self::new_changed(value.original_value, value.present_value)
}
}
impl StorageSlot {
pub fn new(original: StorageValue) -> Self {
Self {
previous_or_original_value: original,
present_value: original,
}
}
pub fn new_changed(
previous_or_original_value: StorageValue,
present_value: StorageValue,
) -> Self {
Self {
previous_or_original_value,
present_value,
}
}
pub fn is_changed(&self) -> bool {
self.previous_or_original_value != self.present_value
}
pub fn original_value(&self) -> StorageValue {
self.previous_or_original_value
}
pub fn present_value(&self) -> StorageValue {
self.present_value
}
}
pub type StorageWithOriginalValues = StorageKeyMap<StorageSlot>;
pub type PlainStorage = StorageKeyMap<StorageValue>;
impl From<AccountInfo> for PlainAccount {
fn from(info: AccountInfo) -> Self {
Self {
info,
storage: HashMap::default(),
}
}
}