use crate::{
SlotChanges, balance_change::BalanceChange, code_change::CodeChange, nonce_change::NonceChange,
};
use alloc::vec::Vec;
use alloy_primitives::{Address, U256};
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[cfg_attr(feature = "rlp", derive(alloy_rlp::RlpEncodable, alloy_rlp::RlpDecodable))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct AccountChanges {
pub address: Address,
pub storage_changes: Vec<SlotChanges>,
pub storage_reads: Vec<U256>,
pub balance_changes: Vec<BalanceChange>,
pub nonce_changes: Vec<NonceChange>,
pub code_changes: Vec<CodeChange>,
}
impl AccountChanges {
pub const fn new(address: Address) -> Self {
Self {
address,
storage_changes: Vec::new(),
storage_reads: Vec::new(),
balance_changes: Vec::new(),
nonce_changes: Vec::new(),
code_changes: Vec::new(),
}
}
pub fn with_capacity(address: Address, capacity: usize) -> Self {
Self {
address,
storage_changes: Vec::with_capacity(capacity),
storage_reads: Vec::with_capacity(capacity),
balance_changes: Vec::with_capacity(capacity),
nonce_changes: Vec::with_capacity(capacity),
code_changes: Vec::with_capacity(capacity),
}
}
#[inline]
pub const fn address(&self) -> Address {
self.address
}
#[inline]
pub fn storage_changes(&self) -> &[SlotChanges] {
&self.storage_changes
}
#[inline]
pub fn storage_reads(&self) -> &[U256] {
&self.storage_reads
}
#[inline]
pub fn balance_changes(&self) -> &[BalanceChange] {
&self.balance_changes
}
#[inline]
pub fn nonce_changes(&self) -> &[NonceChange] {
&self.nonce_changes
}
#[inline]
pub fn code_changes(&self) -> &[CodeChange] {
&self.code_changes
}
pub const fn with_address(mut self, address: Address) -> Self {
self.address = address;
self
}
pub fn with_storage_read(mut self, key: U256) -> Self {
self.storage_reads.push(key);
self
}
pub fn with_storage_change(mut self, change: SlotChanges) -> Self {
self.storage_changes.push(change);
self
}
pub fn with_balance_change(mut self, change: BalanceChange) -> Self {
self.balance_changes.push(change);
self
}
pub fn with_nonce_change(mut self, change: NonceChange) -> Self {
self.nonce_changes.push(change);
self
}
pub fn with_code_change(mut self, change: CodeChange) -> Self {
self.code_changes.push(change);
self
}
pub fn extend_storage_reads<I>(mut self, iter: I) -> Self
where
I: IntoIterator<Item = U256>,
{
self.storage_reads.extend(iter);
self
}
pub fn extend_storage_changes<I>(mut self, iter: I) -> Self
where
I: IntoIterator<Item = SlotChanges>,
{
self.storage_changes.extend(iter);
self
}
}