revm_database/states/
plain_account.rs1use primitives::{HashMap, StorageKey, StorageValue};
2use state::{AccountInfo, EvmStorageSlot};
3
4#[derive(Clone, Debug, Default, PartialEq, Eq)]
6pub struct PlainAccount {
7 pub info: AccountInfo,
8 pub storage: PlainStorage,
9}
10
11impl PlainAccount {
12 pub fn new_empty_with_storage(storage: PlainStorage) -> Self {
13 Self {
14 info: AccountInfo::default(),
15 storage,
16 }
17 }
18
19 pub fn into_components(self) -> (AccountInfo, PlainStorage) {
20 (self.info, self.storage)
21 }
22}
23
24#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash)]
26#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
27pub struct StorageSlot {
28 pub previous_or_original_value: StorageValue,
34 pub present_value: StorageValue,
36}
37
38impl From<EvmStorageSlot> for StorageSlot {
39 fn from(value: EvmStorageSlot) -> Self {
40 Self::new_changed(value.original_value, value.present_value)
41 }
42}
43
44impl StorageSlot {
45 pub fn new(original: StorageValue) -> Self {
47 Self {
48 previous_or_original_value: original,
49 present_value: original,
50 }
51 }
52
53 pub fn new_changed(
55 previous_or_original_value: StorageValue,
56 present_value: StorageValue,
57 ) -> Self {
58 Self {
59 previous_or_original_value,
60 present_value,
61 }
62 }
63
64 pub fn is_changed(&self) -> bool {
66 self.previous_or_original_value != self.present_value
67 }
68
69 pub fn original_value(&self) -> StorageValue {
71 self.previous_or_original_value
72 }
73
74 pub fn present_value(&self) -> StorageValue {
76 self.present_value
77 }
78}
79
80pub type StorageWithOriginalValues = HashMap<StorageKey, StorageSlot>;
84
85pub type PlainStorage = HashMap<StorageKey, StorageValue>;
88
89impl From<AccountInfo> for PlainAccount {
90 fn from(info: AccountInfo) -> Self {
91 Self {
92 info,
93 storage: HashMap::default(),
94 }
95 }
96}