Struct miden_objects::accounts::Account
source · pub struct Account { /* private fields */ }Expand description
An account which can store assets and define rules for manipulating them.
An account consists of the following components:
- Account ID, which uniquely identifies the account and also defines basic properties of the account.
- Account vault, which stores assets owned by the account.
- Account storage, which is a key-value map (both keys and values are words) used to store arbitrary user-defined data.
- Account code, which is a set of Miden VM programs defining the public interface of the account.
- Account nonce, a value which is incremented whenever account state is updated.
Out of the above components account ID is always immutable (once defined it can never be changed). Other components may be mutated throughout the lifetime of the account. However, account state can be changed only by invoking one of account interface methods.
Implementations§
source§impl Account
impl Account
sourcepub fn new(
id: AccountId,
vault: AssetVault,
storage: AccountStorage,
code: AccountCode,
nonce: Felt
) -> Self
pub fn new( id: AccountId, vault: AssetVault, storage: AccountStorage, code: AccountCode, nonce: Felt ) -> Self
Creates and returns a new account initialized with the specified ID, vault, storage, code, and nonce.
sourcepub fn hash(&self) -> Digest
pub fn hash(&self) -> Digest
Returns hash of this account.
Hash of an account is computed as hash(id, nonce, vault_root, storage_root, code_root). Computing the account hash requires 2 permutations of the hash function.
sourcepub fn init_hash(&self) -> Digest
pub fn init_hash(&self) -> Digest
Returns hash of this account as used for the initial account state hash in transaction proofs.
For existing accounts, this is exactly the same as Account::hash(), however, for new accounts this value is set to [ZERO; 4]. This is because when a transaction is executed against a new account, public input for the initial account state is set to [ZERO; 4] to distinguish new accounts from existing accounts. The actual hash of the initial account state (and the initial state itself), are provided to the VM via the advice provider.
sourcepub fn account_type(&self) -> AccountType
pub fn account_type(&self) -> AccountType
Returns the account type
sourcepub fn vault(&self) -> &AssetVault
pub fn vault(&self) -> &AssetVault
Returns a reference to the vault of this account.
sourcepub fn storage(&self) -> &AccountStorage
pub fn storage(&self) -> &AccountStorage
Returns a reference to the storage of this account.
sourcepub fn code(&self) -> &AccountCode
pub fn code(&self) -> &AccountCode
Returns a reference to the code of this account.
sourcepub fn is_regular_account(&self) -> bool
pub fn is_regular_account(&self) -> bool
Returns true if this is a regular account.
sourcepub fn is_on_chain(&self) -> bool
pub fn is_on_chain(&self) -> bool
Returns true if this account is on-chain.
sourcepub fn is_new(&self) -> bool
pub fn is_new(&self) -> bool
Returns true if the account is new (i.e. it has not been initialized yet).
sourcepub fn apply_delta(&mut self, delta: &AccountDelta) -> Result<(), AccountError>
pub fn apply_delta(&mut self, delta: &AccountDelta) -> Result<(), AccountError>
Applies the provided delta to this account. This updates account vault, storage, and nonce to the values specified by the delta.
§Errors
Returns an error if:
- Applying vault sub-delta to the vault of this account fails.
- Applying storage sub-delta to the storage of this account fails.
- The nonce specified in the provided delta smaller than or equal to the current account nonce.
Trait Implementations§
source§impl Deserializable for Account
impl Deserializable for Account
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<&Account> for AccountStub
impl From<&Account> for AccountStub
source§impl From<Account> for AccountStub
impl From<Account> for AccountStub
source§impl PartialEq for Account
impl PartialEq for Account
source§impl Serializable for Account
impl Serializable for Account
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.