miden_objects/account/
partial.rs1use miden_core::Felt;
2use miden_core::utils::{Deserializable, Serializable};
3
4use super::{Account, AccountCode, AccountId, PartialStorage};
5use crate::asset::PartialVault;
6
7#[derive(Clone, Debug, PartialEq, Eq)]
13pub struct PartialAccount {
14 id: AccountId,
16 nonce: Felt,
18 account_code: AccountCode,
20 partial_storage: PartialStorage,
23 partial_vault: PartialVault,
26}
27
28impl PartialAccount {
29 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 pub fn id(&self) -> AccountId {
48 self.id
49 }
50
51 pub fn nonce(&self) -> Felt {
53 self.nonce
54 }
55
56 pub fn code(&self) -> &AccountCode {
58 &self.account_code
59 }
60
61 pub fn storage(&self) -> &PartialStorage {
63 &self.partial_storage
64 }
65
66 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}