alloy_eip7928/
code_change.rs

1//! Contains the [`CodeChange`] struct, which represents a new code for an account.
2//! Single code change: `tx_index` -> `new_code`
3use crate::BlockAccessIndex;
4use alloy_primitives::Bytes;
5
6/// This struct is used to track the new codes of accounts in a block.
7#[derive(Debug, Clone, Default, PartialEq, Eq)]
8#[cfg_attr(feature = "rlp", derive(alloy_rlp::RlpEncodable, alloy_rlp::RlpDecodable))]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize, borsh::BorshDeserialize))]
11#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
12#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
13pub struct CodeChange {
14    /// The index of bal that stores this code change.
15    #[cfg_attr(feature = "serde", serde(alias = "txIndex", with = "crate::quantity"))]
16    pub block_access_index: BlockAccessIndex,
17    /// The new code of the account.
18    pub new_code: Bytes,
19}
20impl CodeChange {
21    /// Creates a new [`CodeChange`].
22    pub const fn new(block_access_index: BlockAccessIndex, new_code: Bytes) -> Self {
23        Self { block_access_index, new_code }
24    }
25
26    /// Returns the bal index.
27    #[inline]
28    pub const fn block_access_index(&self) -> BlockAccessIndex {
29        self.block_access_index
30    }
31
32    /// Returns the new code.
33    #[inline]
34    pub const fn new_code(&self) -> &Bytes {
35        &self.new_code
36    }
37}