Skip to main content

miden_protocol/asset/vault/
asset_id.rs

1use core::fmt::Display;
2
3use crate::Felt;
4
5/// The [`AssetId`] in an [`AssetVaultKey`](crate::asset::AssetVaultKey) distinguishes different
6/// assets issued by the same faucet.
7#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
8pub struct AssetId {
9    suffix: Felt,
10    prefix: Felt,
11}
12
13impl AssetId {
14    /// Constructs an asset ID from its parts.
15    pub fn new(suffix: Felt, prefix: Felt) -> Self {
16        Self { suffix, prefix }
17    }
18
19    /// Returns the suffix of the asset ID.
20    pub fn suffix(&self) -> Felt {
21        self.suffix
22    }
23
24    /// Returns the prefix of the asset ID.
25    pub fn prefix(&self) -> Felt {
26        self.prefix
27    }
28
29    /// Returns `true` if both prefix and suffix are zero, `false` otherwise.
30    pub fn is_empty(&self) -> bool {
31        self.prefix == Felt::ZERO && self.suffix == Felt::ZERO
32    }
33}
34
35impl Display for AssetId {
36    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
37        f.write_fmt(format_args!(
38            "0x{:016x}{:016x}",
39            self.prefix().as_canonical_u64(),
40            self.suffix().as_canonical_u64()
41        ))
42    }
43}