alloy_eip7928/
account_changes.rs1use crate::{
6 SlotChanges, balance_change::BalanceChange, code_change::CodeChange, nonce_change::NonceChange,
7};
8use alloc::vec::Vec;
9use alloy_primitives::{Address, U256};
10
11#[derive(Debug, Clone, Default, PartialEq, Eq)]
13#[cfg_attr(feature = "rlp", derive(alloy_rlp::RlpEncodable, alloy_rlp::RlpDecodable))]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
16#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
17#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
18pub struct AccountChanges {
19 pub address: Address,
21 pub storage_changes: Vec<SlotChanges>,
23 pub storage_reads: Vec<U256>,
25 pub balance_changes: Vec<BalanceChange>,
27 pub nonce_changes: Vec<NonceChange>,
29 pub code_changes: Vec<CodeChange>,
31}
32
33impl AccountChanges {
34 pub const fn new(address: Address) -> Self {
36 Self {
37 address,
38 storage_changes: Vec::new(),
39 storage_reads: Vec::new(),
40 balance_changes: Vec::new(),
41 nonce_changes: Vec::new(),
42 code_changes: Vec::new(),
43 }
44 }
45
46 pub fn with_capacity(address: Address, capacity: usize) -> Self {
48 Self {
49 address,
50 storage_changes: Vec::with_capacity(capacity),
51 storage_reads: Vec::with_capacity(capacity),
52 balance_changes: Vec::with_capacity(capacity),
53 nonce_changes: Vec::with_capacity(capacity),
54 code_changes: Vec::with_capacity(capacity),
55 }
56 }
57
58 #[inline]
60 pub const fn address(&self) -> Address {
61 self.address
62 }
63
64 #[inline]
66 pub fn storage_changes(&self) -> &[SlotChanges] {
67 &self.storage_changes
68 }
69
70 #[inline]
72 pub fn storage_reads(&self) -> &[U256] {
73 &self.storage_reads
74 }
75
76 #[inline]
78 pub fn balance_changes(&self) -> &[BalanceChange] {
79 &self.balance_changes
80 }
81
82 #[inline]
84 pub fn nonce_changes(&self) -> &[NonceChange] {
85 &self.nonce_changes
86 }
87
88 #[inline]
90 pub fn code_changes(&self) -> &[CodeChange] {
91 &self.code_changes
92 }
93
94 pub const fn with_address(mut self, address: Address) -> Self {
96 self.address = address;
97 self
98 }
99
100 pub fn with_storage_read(mut self, key: U256) -> Self {
102 self.storage_reads.push(key);
103 self
104 }
105
106 pub fn with_storage_change(mut self, change: SlotChanges) -> Self {
108 self.storage_changes.push(change);
109 self
110 }
111
112 pub fn with_balance_change(mut self, change: BalanceChange) -> Self {
114 self.balance_changes.push(change);
115 self
116 }
117
118 pub fn with_nonce_change(mut self, change: NonceChange) -> Self {
120 self.nonce_changes.push(change);
121 self
122 }
123
124 pub fn with_code_change(mut self, change: CodeChange) -> Self {
126 self.code_changes.push(change);
127 self
128 }
129
130 pub fn extend_storage_reads<I>(mut self, iter: I) -> Self
132 where
133 I: IntoIterator<Item = U256>,
134 {
135 self.storage_reads.extend(iter);
136 self
137 }
138
139 pub fn extend_storage_changes<I>(mut self, iter: I) -> Self
141 where
142 I: IntoIterator<Item = SlotChanges>,
143 {
144 self.storage_changes.extend(iter);
145 self
146 }
147}