Skip to main content

alloy_eip7928/
nonce_change.rs

1//! Contains the [`NonceChange`] struct, which represents a new nonce for an account.
2//! Single nonce 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, Hash)]
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(
16        feature = "serde",
17        serde(rename = "index", alias = "blockAccessIndex", alias = "txIndex")
18    )]
19    pub block_access_index: BlockAccessIndex,
20    /// The new nonce of the account.
21    #[cfg_attr(
22        feature = "serde",
23        serde(rename = "value", alias = "newNonce", alias = "postNonce", with = "crate::quantity")
24    )]
25    pub new_nonce: u64,
26}
27
28impl NonceChange {
29    /// Creates a new [`NonceChange`].
30    pub const fn new(block_access_index: BlockAccessIndex, new_nonce: u64) -> Self {
31        Self { block_access_index, new_nonce }
32    }
33
34    /// Returns the bal index.
35    pub const fn block_access_index(&self) -> BlockAccessIndex {
36        self.block_access_index
37    }
38
39    /// Returns the new nonce.
40    pub const fn new_nonce(&self) -> u64 {
41        self.new_nonce
42    }
43}