miden_objects/decoded/account/
partial.rs1pub use proto::account::DecodedPartialStorageMap as PartialStorageMap;
2
3use crate::decoded::VerificationError;
4use crate::{Verify, proto};
5
6#[cfg(test)]
7mod tests;
8
9impl Verify for PartialStorageMap {
10 type Verified = miden_protocol::account::PartialStorageMap;
11 type Error = VerificationError;
12 fn verify(self) -> Result<Self::Verified, Self::Error> {
13 Ok(Self::Verified::try_from_parts(
14 self.smt.verify()?,
15 self.keys.map(miden_protocol::account::StorageMapKey::from_raw),
16 )?)
17 }
18}
19
20pub use proto::account::DecodedPartialStorage as PartialStorage;
21
22impl Verify for PartialStorage {
23 type Verified = miden_protocol::account::PartialStorage;
24 type Error = VerificationError;
25 fn verify(self) -> Result<Self::Verified, Self::Error> {
26 let mut roots = alloc::collections::BTreeSet::new();
27 let mut maps = alloc::vec::Vec::new();
28 for map in self.maps.into_inner() {
29 let map = map.verify()?;
30 if !roots.insert(map.root()) {
31 return Err(PartialStorageError::DuplicateRoot(map.root()).into());
32 }
33 maps.push(map);
34 }
35 Ok(Self::Verified::new(self.header.verify()?, maps)?)
36 }
37}
38
39#[derive(Debug, thiserror::Error)]
40pub enum PartialStorageError {
41 #[error("duplicate partial storage map root {0}")]
42 DuplicateRoot(miden_protocol::Word),
43}
44
45pub use proto::account::DecodedPartialVault as PartialVault;
46
47impl Verify for PartialVault {
48 type Verified = miden_protocol::asset::PartialVault;
49 type Error = VerificationError;
50 fn verify(self) -> Result<Self::Verified, Self::Error> {
51 let ids = self.asset_ids.try_map(miden_protocol::asset::AssetId::try_from)?;
52 Ok(Self::Verified::try_from_parts(self.smt.verify()?, ids)?)
53 }
54}
55
56pub use proto::account::DecodedPartialAccount as PartialAccount;
57
58impl Verify for PartialAccount {
59 type Verified = miden_protocol::account::PartialAccount;
60 type Error = VerificationError;
61 fn verify(self) -> Result<Self::Verified, Self::Error> {
62 Ok(Self::Verified::new(
63 self.account_id.verify()?,
64 self.nonce,
65 self.code.verify()?,
66 self.storage.verify()?,
67 self.vault.verify()?,
68 self.seed.into_inner(),
69 )?)
70 }
71}