ethrex_common/types/
account_update.rs1use crate::seeded_hash::SeededHashMap;
2use crate::{
3 Address, H256, U256,
4 types::{AccountInfo, Code},
5};
6use serde::{Deserialize, Serialize};
7
8#[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
9pub struct AccountUpdate {
10 pub address: Address,
11 pub removed: bool,
12 pub info: Option<AccountInfo>,
13 pub code: Option<Code>,
14 pub added_storage: SeededHashMap<H256, U256>,
16 pub removed_storage: bool,
18 }
21
22impl AccountUpdate {
23 pub fn new(address: Address) -> AccountUpdate {
25 AccountUpdate {
26 address,
27 ..Default::default()
28 }
29 }
30
31 pub fn removed(address: Address) -> AccountUpdate {
33 AccountUpdate {
34 address,
35 removed: true,
36 ..Default::default()
37 }
38 }
39
40 pub fn merge(&mut self, other: AccountUpdate) {
41 self.removed = other.removed;
42 self.removed_storage |= other.removed_storage;
43 if let Some(info) = other.info {
44 self.info = Some(info);
45 }
46 if let Some(code) = other.code {
47 self.code = Some(code);
48 }
49 for (key, value) in other.added_storage {
50 self.added_storage.insert(key, value);
51 }
52 }
53}