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). This field element uniquely identifies a single account and also specifies the type of the underlying account. Specifically:
- The two most significant bits of the ID specify the type of the account:
- 00 - regular account with updatable code.
- 01 - regular account with immutable code.
- 10 - fungible asset faucet with immutable code.
- 11 - non-fungible asset faucet with immutable code.
- The third most significant bit of the ID specifies whether the account data is stored on-chain:
- 0 - full account data is stored on-chain.
- 1 - only the account hash is stored on-chain which serves as a commitment to the account state. As such the three most significant bits fully describes the type of the account.
Implementations§
source§impl AccountId
impl AccountId
pub const FUNGIBLE_FAUCET_TAG: u64 = 2u64
pub const NON_FUNGIBLE_FAUCET_TAG: u64 = 3u64
pub const REGULAR_ACCOUNT_UPDATABLE_CODE_TAG: u64 = 0u64
pub const REGULAR_ACCOUNT_IMMUTABLE_CODE_TAG: u64 = 1u64
pub const ON_CHAIN_ACCOUNT_SELECTOR: u64 = 1u64
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 3 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 ID has at least
5ones. - the ID has at least
23trailing zeros if it is a regular account. - the ID has at least
31trailing zeros if it is a faucet account.
sourcepub fn new_unchecked(value: Felt) -> AccountId
pub fn new_unchecked(value: Felt) -> AccountId
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 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,
on_chain: bool,
code_root: Digest,
storage_root: Digest
) -> Result<Word, AccountError>
pub fn get_account_seed( init_seed: [u8; 32], account_type: AccountType, on_chain: bool, 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.
sourcepub fn validate_seed_digest(digest: &Digest) -> Result<(), AccountError>
pub fn validate_seed_digest(digest: &Digest) -> Result<(), AccountError>
Returns an error if:
- There are fewer then:
- 24 trailing ZEROs in the last element of the seed digest for regular accounts.
- 32 trailing ZEROs in the last element of the seed digest for faucet accounts.
- There are fewer than 5 ONEs in the account ID (first element of the seed digest).
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.