alloy_eip7928/
balance_change.rs

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