miden_objects/account/
partial.rs

1use miden_core::Felt;
2use miden_core::utils::{Deserializable, Serializable};
3
4use super::{Account, AccountCode, AccountId, PartialStorage};
5use crate::asset::PartialVault;
6
7/// A partial representation of an account.
8///
9/// A partial account is used as inputs to the transaction kernel and contains only the essential
10/// data needed for verification and transaction processing without requiring the full account
11/// state.
12#[derive(Clone, Debug, PartialEq, Eq)]
13pub struct PartialAccount {
14    /// The ID for the partial account
15    id: AccountId,
16    /// The current transaction nonce of the account
17    nonce: Felt,
18    /// Account code
19    account_code: AccountCode,
20    /// Partial representation of the account's storage, containing the storage commitment and
21    /// proofs for specific storage slots that need to be accessed
22    partial_storage: PartialStorage,
23    /// Partial representation of the account's vault, containing the vault root and necessary
24    /// proof information for asset verification
25    partial_vault: PartialVault,
26}
27
28impl PartialAccount {
29    /// Creates a new instance of a partial account with the specified components.
30    pub fn new(
31        id: AccountId,
32        nonce: Felt,
33        account_code: AccountCode,
34        partial_storage: PartialStorage,
35        partial_vault: PartialVault,
36    ) -> Self {
37        Self {
38            id,
39            nonce,
40            account_code,
41            partial_storage,
42            partial_vault,
43        }
44    }
45
46    /// Returns the account's unique identifier.
47    pub fn id(&self) -> AccountId {
48        self.id
49    }
50
51    /// Returns the account's current nonce value.
52    pub fn nonce(&self) -> Felt {
53        self.nonce
54    }
55
56    /// Returns a reference to the account code.
57    pub fn code(&self) -> &AccountCode {
58        &self.account_code
59    }
60
61    /// Returns a reference to the partial storage representation of the account.
62    pub fn storage(&self) -> &PartialStorage {
63        &self.partial_storage
64    }
65
66    /// Returns a reference to the partial vault representation of the account.
67    pub fn vault(&self) -> &PartialVault {
68        &self.partial_vault
69    }
70}
71
72impl From<Account> for PartialAccount {
73    fn from(account: Account) -> Self {
74        PartialAccount::from(&account)
75    }
76}
77
78impl From<&Account> for PartialAccount {
79    fn from(account: &Account) -> Self {
80        PartialAccount::new(
81            account.id(),
82            account.nonce(),
83            account.code().clone(),
84            account.storage().into(),
85            account.vault().into(),
86        )
87    }
88}
89
90impl Serializable for PartialAccount {
91    fn write_into<W: miden_core::utils::ByteWriter>(&self, target: &mut W) {
92        target.write(self.id);
93        target.write(self.nonce);
94        target.write(&self.account_code);
95        target.write(&self.partial_storage);
96        target.write(&self.partial_vault);
97    }
98}
99
100impl Deserializable for PartialAccount {
101    fn read_from<R: miden_core::utils::ByteReader>(
102        source: &mut R,
103    ) -> Result<Self, miden_processor::DeserializationError> {
104        let account_id = source.read()?;
105        let nonce = source.read()?;
106        let account_code = source.read()?;
107        let partial_storage = source.read()?;
108        let partial_vault = source.read()?;
109
110        Ok(PartialAccount {
111            id: account_id,
112            nonce,
113            account_code,
114            partial_storage,
115            partial_vault,
116        })
117    }
118}