reth_trie_common/bundle_state/
plain_account.rs1use alloy_primitives::{
2 map::{HashMap, U256Map},
3 U256,
4};
5use evm2::evm::AccountInfo;
6
7#[derive(Clone, Debug, Default, PartialEq, Eq)]
9pub struct PlainAccount {
10 pub info: AccountInfo,
12 pub storage: PlainStorage,
14}
15
16impl PlainAccount {
17 pub fn new_empty_with_storage(storage: PlainStorage) -> Self {
19 Self { info: AccountInfo::default(), storage }
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: U256,
38 pub present_value: U256,
40}
41
42impl StorageSlot {
43 pub const fn new(original: U256) -> Self {
45 Self { previous_or_original_value: original, present_value: original }
46 }
47
48 pub const fn new_changed(previous_or_original_value: U256, present_value: U256) -> Self {
50 Self { previous_or_original_value, present_value }
51 }
52
53 pub fn is_changed(&self) -> bool {
55 self.previous_or_original_value != self.present_value
56 }
57
58 pub const fn original_value(&self) -> U256 {
60 self.previous_or_original_value
61 }
62
63 pub const fn present_value(&self) -> U256 {
65 self.present_value
66 }
67}
68
69pub type StorageWithOriginalValues = U256Map<StorageSlot>;
73
74pub type PlainStorage = U256Map<U256>;
77
78impl From<AccountInfo> for PlainAccount {
79 fn from(info: AccountInfo) -> Self {
80 Self { info, storage: HashMap::default() }
81 }
82}