miden_objects/block/
block_account_update.rs

1use crate::Word;
2use crate::account::AccountId;
3use crate::account::delta::AccountUpdateDetails;
4use crate::utils::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable};
5
6// BLOCK ACCOUNT UPDATE
7// ================================================================================================
8
9/// Describes the changes made to an account state resulting from executing transactions contained
10/// in a block.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct BlockAccountUpdate {
13    /// ID of the updated account.
14    account_id: AccountId,
15
16    /// Final commitment to the new state of the account after this update.
17    final_state_commitment: Word,
18
19    /// A set of changes which can be applied to the previous account state (i.e., the state as of
20    /// the last block) to get the new account state. For private accounts, this is set to
21    /// [AccountUpdateDetails::Private].
22    details: AccountUpdateDetails,
23}
24
25impl BlockAccountUpdate {
26    /// Returns a new [BlockAccountUpdate] instantiated from the specified components.
27    pub const fn new(
28        account_id: AccountId,
29        final_state_commitment: Word,
30        details: AccountUpdateDetails,
31    ) -> Self {
32        Self {
33            account_id,
34            final_state_commitment,
35            details,
36        }
37    }
38
39    /// Returns the ID of the updated account.
40    pub fn account_id(&self) -> AccountId {
41        self.account_id
42    }
43
44    /// Returns the state commitment of the account after this update.
45    pub fn final_state_commitment(&self) -> Word {
46        self.final_state_commitment
47    }
48
49    /// Returns the description of the updates for on-chain accounts.
50    ///
51    /// These descriptions can be used to build the new account state from the previous account
52    /// state.
53    pub fn details(&self) -> &AccountUpdateDetails {
54        &self.details
55    }
56
57    /// Returns `true` if the account update details are for private account.
58    pub fn is_private(&self) -> bool {
59        self.details.is_private()
60    }
61}
62
63impl Serializable for BlockAccountUpdate {
64    fn write_into<W: ByteWriter>(&self, target: &mut W) {
65        self.account_id.write_into(target);
66        self.final_state_commitment.write_into(target);
67        self.details.write_into(target);
68    }
69}
70
71impl Deserializable for BlockAccountUpdate {
72    fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
73        Ok(Self {
74            account_id: AccountId::read_from(source)?,
75            final_state_commitment: Word::read_from(source)?,
76            details: AccountUpdateDetails::read_from(source)?,
77        })
78    }
79}