miden_objects/account/
partial.rs1use vm_core::{
2 Felt,
3 utils::{Deserializable, Serializable},
4};
5
6use super::{Account, AccountCode, AccountId, PartialStorage};
7use crate::asset::PartialVault;
8
9#[derive(Clone, Debug, PartialEq, Eq)]
15pub struct PartialAccount {
16 id: AccountId,
18 nonce: Felt,
20 account_code: AccountCode,
22 partial_storage: PartialStorage,
25 partial_vault: PartialVault,
28}
29
30impl PartialAccount {
31 pub fn new(
33 id: AccountId,
34 nonce: Felt,
35 account_code: AccountCode,
36 partial_storage: PartialStorage,
37 partial_vault: PartialVault,
38 ) -> Self {
39 Self {
40 id,
41 nonce,
42 account_code,
43 partial_storage,
44 partial_vault,
45 }
46 }
47
48 pub fn id(&self) -> AccountId {
50 self.id
51 }
52
53 pub fn nonce(&self) -> Felt {
55 self.nonce
56 }
57
58 pub fn code(&self) -> &AccountCode {
60 &self.account_code
61 }
62
63 pub fn storage(&self) -> &PartialStorage {
65 &self.partial_storage
66 }
67
68 pub fn vault(&self) -> &PartialVault {
70 &self.partial_vault
71 }
72}
73
74impl From<Account> for PartialAccount {
75 fn from(account: Account) -> Self {
76 PartialAccount::from(&account)
77 }
78}
79
80impl From<&Account> for PartialAccount {
81 fn from(account: &Account) -> Self {
82 PartialAccount::new(
83 account.id(),
84 account.nonce(),
85 account.code().clone(),
86 account.storage().into(),
87 account.vault().into(),
88 )
89 }
90}
91
92impl Serializable for PartialAccount {
93 fn write_into<W: vm_core::utils::ByteWriter>(&self, target: &mut W) {
94 target.write(self.id);
95 target.write(self.nonce);
96 target.write(&self.account_code);
97 target.write(&self.partial_storage);
98 target.write(&self.partial_vault);
99 }
100}
101
102impl Deserializable for PartialAccount {
103 fn read_from<R: vm_core::utils::ByteReader>(
104 source: &mut R,
105 ) -> Result<Self, vm_processor::DeserializationError> {
106 let account_id = source.read()?;
107 let nonce = source.read()?;
108 let account_code = source.read()?;
109 let partial_storage = source.read()?;
110 let partial_vault = source.read()?;
111
112 Ok(PartialAccount {
113 id: account_id,
114 nonce,
115 account_code,
116 partial_storage,
117 partial_vault,
118 })
119 }
120}