Struct miden_objects::accounts::AccountId
source · pub struct AccountId(/* private fields */);Expand description
Unique identifier of an account.
Account ID consists of 1 field element (~64 bits). The most significant bits in the id are used to encode the account’ storage and type.
The top two bits are used to encode the storage type. The values [OFF_CHAIN] and [ON_CHAIN] encode the account’s storage type. The next two bits encode the account type. The values [FUNGIBLE_FAUCET], [NON_FUNGIBLE_FAUCET], [REGULAR_ACCOUNT_IMMUTABLE_CODE], and [REGULAR_ACCOUNT_UPDATABLE_CODE] encode the account’s type.
Implementations§
source§impl AccountId
impl AccountId
sourcepub const REGULAR_ACCOUNT_SEED_DIGEST_MIN_TRAILING_ZEROS: u32 = 23u32
pub const REGULAR_ACCOUNT_SEED_DIGEST_MIN_TRAILING_ZEROS: u32 = 23u32
Specifies a minimum number of trailing zeros required in the last element of the seed digest.
Note: The account id includes 4 bits of metadata, these bits determine the account type (normal account, fungible token, non-fungible token), the storage type (on/off chain), and for the normal accounts if the code is updatable or not. These metadata bits are also checked by the PoW and add to the total work defined below.
pub const FAUCET_SEED_DIGEST_MIN_TRAILING_ZEROS: u32 = 31u32
sourcepub const MIN_ACCOUNT_ONES: u32 = 5u32
pub const MIN_ACCOUNT_ONES: u32 = 5u32
Specifies a minimum number of ones for a valid account ID.
sourcepub fn new(
seed: Word,
code_root: Digest,
storage_root: Digest
) -> Result<Self, AccountError>
pub fn new( seed: Word, code_root: Digest, storage_root: Digest ) -> Result<Self, AccountError>
Returns a new account ID derived from the specified seed, code root and storage root.
The account ID is computed by hashing the seed, code root and storage root and using 1
element of the resulting digest to form the ID. Specifically we take element 0. We also
require that the last element of the seed digest has at least 23 trailing zeros if it
is a regular account, or 31 trailing zeros if it is a faucet account.
The seed digest is computed using a sequential hash over hash(SEED, CODE_ROOT, STORAGE_ROOT, ZERO). This takes two permutations.
§Errors
Returns an error if the resulting account ID does not comply with account ID rules:
- the metadata embedded in the ID (i.e., the first 4 bits) is valid.
- the ID has at least
5ones. - the last element of the seed digest has at least
23trailing zeros for regular accounts. - the last element of the seed digest has at least
31trailing zeros for faucet accounts.
sourcepub fn new_unchecked(value: Felt) -> Self
pub fn new_unchecked(value: Felt) -> Self
sourcepub fn account_type(&self) -> AccountType
pub fn account_type(&self) -> AccountType
Returns the type of this account ID.
sourcepub fn is_faucet(&self) -> bool
pub fn is_faucet(&self) -> bool
Returns true if an account with this ID is a faucet (can issue assets).
sourcepub fn is_regular_account(&self) -> bool
pub fn is_regular_account(&self) -> bool
Returns true if an account with this ID is a regular account.
sourcepub fn storage_type(&self) -> AccountStorageType
pub fn storage_type(&self) -> AccountStorageType
Returns the storage type of this account (e.g., on-chain or off-chain).
sourcepub fn is_on_chain(&self) -> bool
pub fn is_on_chain(&self) -> bool
Returns true if an account with this ID is an on-chain account.
sourcepub fn get_account_seed(
init_seed: [u8; 32],
account_type: AccountType,
storage_type: AccountStorageType,
code_root: Digest,
storage_root: Digest
) -> Result<Word, AccountError>
pub fn get_account_seed( init_seed: [u8; 32], account_type: AccountType, storage_type: AccountStorageType, code_root: Digest, storage_root: Digest ) -> Result<Word, AccountError>
Finds and returns a seed suitable for creating an account ID for the specified account type using the provided initial seed as a starting point.
Trait Implementations§
source§impl Deserializable for AccountId
impl Deserializable for AccountId
source§fn read_from<R: ByteReader>(
source: &mut R
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R ) -> Result<Self, DeserializationError>
source, attempts to deserialize these bytes
into Self, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl From<AccountId> for LeafIndex<ACCOUNT_TREE_DEPTH>
impl From<AccountId> for LeafIndex<ACCOUNT_TREE_DEPTH>
Account IDs are used as indexes in the account database, which is a tree of depth 64.
source§impl Ord for AccountId
impl Ord for AccountId
source§impl PartialEq for AccountId
impl PartialEq for AccountId
source§impl PartialOrd for AccountId
impl PartialOrd for AccountId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl Serializable for AccountId
impl Serializable for AccountId
source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self into bytes and writes these bytes into the target.source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
source§impl TryFrom<BaseElement> for AccountId
impl TryFrom<BaseElement> for AccountId
source§fn try_from(value: Felt) -> Result<Self, Self::Error>
fn try_from(value: Felt) -> Result<Self, Self::Error>
Returns an AccountId instantiated with the provided field element.
§Errors
Returns an error if:
- If there are fewer than AccountId::MIN_ACCOUNT_ONES in the provided value.
- If the provided value contains invalid account ID metadata (i.e., the first 4 bits).