alloy_eip7928/
nonce_change.rs

1//! Contains the [`NonceChange`] struct, which represents a new nonce for an account.
2//! Single code change: `tx_index` -> `new_nonce`
3
4use crate::BlockAccessIndex;
5
6/// This struct is used to track the new nonce 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 NonceChange {
14    /// The index of bal that stores this nonce 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    #[cfg_attr(feature = "serde", serde(alias = "postNonce", with = "crate::quantity"))]
19    pub new_nonce: u64,
20}
21
22impl NonceChange {
23    /// Creates a new [`NonceChange`].
24    pub const fn new(block_access_index: BlockAccessIndex, new_nonce: u64) -> Self {
25        Self { block_access_index, new_nonce }
26    }
27
28    /// Returns the bal index.
29    pub const fn block_access_index(&self) -> BlockAccessIndex {
30        self.block_access_index
31    }
32
33    /// Returns the new nonce.
34    pub const fn new_nonce(&self) -> u64 {
35        self.new_nonce
36    }
37}