alloy-eip7928 0.4.0

Implementation of EIP-7928 type definitions
Documentation
//! Contains the [`NonceChange`] struct, which represents a new nonce for an account.
//! Single nonce change: `tx_index` -> `new_nonce`

use crate::BlockAccessIndex;

/// This struct is used to track the new nonce of accounts in a block.
#[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 NonceChange {
    /// The index of bal that stores this nonce change.
    #[cfg_attr(feature = "serde", serde(alias = "txIndex"))]
    pub block_access_index: BlockAccessIndex,
    /// The new nonce of the account.
    #[cfg_attr(feature = "serde", serde(alias = "postNonce", with = "crate::quantity"))]
    pub new_nonce: u64,
}

impl NonceChange {
    /// Creates a new [`NonceChange`].
    pub const fn new(block_access_index: BlockAccessIndex, new_nonce: u64) -> Self {
        Self { block_access_index, new_nonce }
    }

    /// Returns the bal index.
    pub const fn block_access_index(&self) -> BlockAccessIndex {
        self.block_access_index
    }

    /// Returns the new nonce.
    pub const fn new_nonce(&self) -> u64 {
        self.new_nonce
    }
}