revm_database/states/
plain_account.rs1use primitives::{HashMap, U256};
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: U256,
34 pub present_value: U256,
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: U256) -> Self {
47 Self {
48 previous_or_original_value: original,
49 present_value: original,
50 }
51 }
52
53 pub fn new_changed(previous_or_original_value: U256, present_value: U256) -> Self {
55 Self {
56 previous_or_original_value,
57 present_value,
58 }
59 }
60
61 pub fn is_changed(&self) -> bool {
63 self.previous_or_original_value != self.present_value
64 }
65
66 pub fn original_value(&self) -> U256 {
68 self.previous_or_original_value
69 }
70
71 pub fn present_value(&self) -> U256 {
73 self.present_value
74 }
75}
76
77pub type StorageWithOriginalValues = HashMap<U256, StorageSlot>;
81
82pub type PlainStorage = HashMap<U256, U256>;
85
86impl From<AccountInfo> for PlainAccount {
87 fn from(info: AccountInfo) -> Self {
88 Self {
89 info,
90 storage: HashMap::default(),
91 }
92 }
93}