use crate::primitives::{AccountInfo, EvmStorageSlot, HashMap, U256};
#[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: U256,
pub present_value: U256,
}
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: U256) -> Self {
Self {
previous_or_original_value: original,
present_value: original,
}
}
pub fn new_changed(previous_or_original_value: U256, present_value: U256) -> 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) -> U256 {
self.previous_or_original_value
}
pub fn present_value(&self) -> U256 {
self.present_value
}
}
pub type StorageWithOriginalValues = HashMap<U256, StorageSlot>;
pub type PlainStorage = HashMap<U256, U256>;
impl From<AccountInfo> for PlainAccount {
fn from(info: AccountInfo) -> Self {
Self {
info,
storage: HashMap::default(),
}
}
}