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

source

pub const FUNGIBLE_FAUCET_TAG: u64 = 2u64

source

pub const NON_FUNGIBLE_FAUCET_TAG: u64 = 3u64

source

pub const REGULAR_ACCOUNT_UPDATABLE_CODE_TAG: u64 = 0u64

source

pub const REGULAR_ACCOUNT_IMMUTABLE_CODE_TAG: u64 = 1u64

source

pub const ON_CHAIN_ACCOUNT_SELECTOR: u64 = 1u64

source

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.

source

pub const FAUCET_SEED_DIGEST_MIN_TRAILING_ZEROS: u32 = 31u32

source

pub const MIN_ACCOUNT_ONES: u32 = 5u32

Specifies a minimum number of ones for a valid account ID.

source

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 5 ones.
  • the ID has at least 23 trailing zeros if it is a regular account.
  • the ID has at least 31 trailing zeros if it is a faucet account.
source

pub fn new_unchecked(value: Felt) -> AccountId

Creates a new AccountId without checking its validity.

This function requires that the provided value is a valid Felt representation of an AccountId.

source

pub fn account_type(&self) -> AccountType

Returns the type of this account ID.

source

pub fn is_faucet(&self) -> bool

Returns true if an account with this ID is a faucet (can issue assets).

source

pub fn is_regular_account(&self) -> bool

Returns true if an account with this ID is a regular account.

source

pub fn is_on_chain(&self) -> bool

Returns true if an account with this ID is an on-chain account.

source

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.

source

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).
source

pub fn from_hex(hex_value: &str) -> Result<AccountId, AccountError>

Creates an Account Id from a hex string. Assumes the string starts with “0x” and that the hexadecimal characters are big-endian encoded.

source

pub fn to_hex(&self) -> String

Returns a big-endian, hex-encoded string.

Trait Implementations§

source§

impl Clone for AccountId

source§

fn clone(&self) -> AccountId

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for AccountId

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deserializable for AccountId

source§

fn read_from<R: ByteReader>( source: &mut R ) -> Result<Self, DeserializationError>

Reads a sequence of bytes from the provided source, attempts to deserialize these bytes into Self, and returns the result. Read more
source§

fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>

Attempts to deserialize the provided bytes into Self and returns the result. Read more
source§

impl Display for AccountId

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<AccountId> for [u8; 8]

source§

fn from(id: AccountId) -> Self

Converts to this type from the input type.
source§

impl From<AccountId> for Felt

source§

fn from(id: AccountId) -> Self

Converts to this type from the input type.
source§

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§

fn from(id: AccountId) -> Self

Converts to this type from the input type.
source§

impl From<AccountId> for u64

source§

fn from(id: AccountId) -> Self

Converts to this type from the input type.
source§

impl Ord for AccountId

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for AccountId

source§

fn eq(&self, other: &AccountId) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for AccountId

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serializable for AccountId

source§

fn write_into<W: ByteWriter>(&self, target: &mut W)

Serializes self into bytes and writes these bytes into the target.
source§

fn to_bytes(&self) -> Vec<u8>

Serializes self into a vector of bytes.
source§

fn get_size_hint(&self) -> usize

Returns an estimate of how many bytes are needed to represent self. Read more
source§

impl TryFrom<[u8; 8]> for AccountId

§

type Error = AccountError

The type returned in the event of a conversion error.
source§

fn try_from(value: [u8; 8]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<BaseElement> for AccountId

§

type Error = AccountError

The type returned in the event of a conversion error.
source§

fn try_from(value: Felt) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<u64> for AccountId

§

type Error = AccountError

The type returned in the event of a conversion error.
source§

fn try_from(value: u64) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for AccountId

source§

impl Eq for AccountId

source§

impl StructuralPartialEq for AccountId

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more