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,
9 pub storage: PlainStorage,
11}
12
13impl PlainAccount {
14 pub fn new_empty_with_storage(storage: PlainStorage) -> Self {
16 Self {
17 info: AccountInfo::default(),
18 storage,
19 }
20 }
21
22 pub fn into_components(self) -> (AccountInfo, PlainStorage) {
24 (self.info, self.storage)
25 }
26}
27
28#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash)]
30#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31pub struct StorageSlot {
32 pub previous_or_original_value: StorageValue,
38 pub present_value: StorageValue,
40}
41
42impl From<EvmStorageSlot> for StorageSlot {
43 fn from(value: EvmStorageSlot) -> Self {
44 Self::new_changed(value.original_value, value.present_value)
45 }
46}
47
48impl StorageSlot {
49 pub fn new(original: StorageValue) -> Self {
51 Self {
52 previous_or_original_value: original,
53 present_value: original,
54 }
55 }
56
57 pub fn new_changed(
59 previous_or_original_value: StorageValue,
60 present_value: StorageValue,
61 ) -> Self {
62 Self {
63 previous_or_original_value,
64 present_value,
65 }
66 }
67
68 pub fn is_changed(&self) -> bool {
70 self.previous_or_original_value != self.present_value
71 }
72
73 pub fn original_value(&self) -> StorageValue {
75 self.previous_or_original_value
76 }
77
78 pub fn present_value(&self) -> StorageValue {
80 self.present_value
81 }
82}
83
84pub type StorageWithOriginalValues = HashMap<StorageKey, StorageSlot>;
88
89pub type PlainStorage = HashMap<StorageKey, StorageValue>;
92
93impl From<AccountInfo> for PlainAccount {
94 fn from(info: AccountInfo) -> Self {
95 Self {
96 info,
97 storage: HashMap::default(),
98 }
99 }
100}