Skip to main content

Module iota::account

use iota::address; use iota::authenticator_function; use iota::dynamic_field; use iota::event; use iota::hex; use iota::object; use iota::package_metadata; use iota::tx_context; use iota::vec_map; use std::address; use std::ascii; use std::bcs; use std::option; use std::string; use std::type_name; use std::vector;

Struct ImmutableAccountCreated

Event: emitted when a new immutable account has been created.

public struct ImmutableAccountCreated<phantom Account: key> has copy, drop

Fields

Struct MutableAccountCreated

Event: emitted when a new mutable account has been created.

public struct MutableAccountCreated<phantom Account: key> has copy, drop

Fields

Struct AuthenticatorFunctionRefV1Rotated

Event: emitted when an account authenticator has been rotated.

public struct AuthenticatorFunctionRefV1Rotated<phantom Account: key> has copy, drop

Fields

Struct AuthenticatorFunctionRefV1Key

Dynamic field key, where the system will look for a potential authenticate function.

public struct AuthenticatorFunctionRefV1Key has copy, drop, store

Fields

Constants

#[error] const EAuthenticatorFunctionRefV1AlreadyAttached: vector<u8> = b"An AuthenticatorFunctionRefV1 instance is already attached to the account.";

#[error] const EAuthenticatorFunctionRefV1NotAttached: vector<u8> = b"'AuthenticatorFunctionRefV1' is not attached to the account.";

Function create_account_v1

Create an account as a mutable shared object with the provided authenticator. The authenticator instance will be added to the account as a dynamic field specified by the AuthenticatorFunctionRefV1Key name. This function has custom rules performed by the IOTA Move bytecode verifier that ensures that Account is an object defined in the module where create_account_v1 is invoked. Emits an MutableAccountCreated event upon success.

public fun create_account_v1<Account: key>(account: Account, authenticator: iota::authenticator_function::AuthenticatorFunctionRefV1<Account>)

Implementation

public fun create_account_v1<Account: key>( mut account: Account, authenticator: AuthenticatorFunctionRefV1<Account>, ) { let event = MutableAccountCreated { account_id: *object::borrow_id(&account), authenticator, }; attach_auth_function_ref_v1(&mut account, authenticator); create_account_v1_impl(account); event::emit(event); }

Function create_immutable_account_v1

Create an account as an immutable object with the provided authenticator. The authenticator instance will be added to the account as a dynamic field specified by the AuthenticatorFunctionRefV1Key name. This function has custom rules performed by the IOTA Move bytecode verifier that ensures that Account is an object defined in the module where create_immutable_account_v1 is invoked. Emits an ImmutableAccountCreated event upon success.

public fun create_immutable_account_v1<Account: key>(account: Account, authenticator: iota::authenticator_function::AuthenticatorFunctionRefV1<Account>)

Implementation

public fun create_immutable_account_v1<Account: key>( mut account: Account, authenticator: AuthenticatorFunctionRefV1<Account>, ) { let event = ImmutableAccountCreated { account_id: *object::borrow_id(&account), authenticator, }; attach_auth_function_ref_v1(&mut account, authenticator); create_immutable_account_v1_impl(account); event::emit(event); }

Function rotate_auth_function_ref_v1

Rotate the account-related authenticator. The authenticator instance will replace the account dynamic field specified by the AuthenticatorFunctionRefV1Key name. This function has custom rules performed by the IOTA Move bytecode verifier that ensures that Account is an object defined in the module where rotate_auth_function_ref_v1 is invoked. Emits an AuthenticatorFunctionRefV1Rotated event upon success.

public fun rotate_auth_function_ref_v1<Account: key>(account: &mut Account, authenticator: iota::authenticator_function::AuthenticatorFunctionRefV1<Account>): iota::authenticator_function::AuthenticatorFunctionRefV1<Account>

Implementation

public fun rotate_auth_function_ref_v1<Account: key>( account: &mut Account, authenticator: AuthenticatorFunctionRefV1<Account>, ): AuthenticatorFunctionRefV1<Account> { let account_id = borrow_account_uid_mut(account); assert!(has_auth_function_ref_v1(account_id), EAuthenticatorFunctionRefV1NotAttached); let name = auth_function_ref_v1_key(); let prev = dynamic_field::remove(account_id, name); let event = AuthenticatorFunctionRefV1Rotated { account_id: *account_id.as_inner(), from: prev, to: authenticator, }; dynamic_field::add(account_id, name, authenticator); event::emit(event); prev }

Function borrow_auth_function_ref_v1

Borrow the account-related authenticator. The dynamic field specified by the AuthenticatorFunctionRefV1Key name will be returned.

public fun borrow_auth_function_ref_v1<Account: key>(account_id: &iota::object::UID): &iota::authenticator_function::AuthenticatorFunctionRefV1<Account>

Implementation

public fun borrow_auth_function_ref_v1<Account: key>( account_id: &UID, ): &AuthenticatorFunctionRefV1<Account> { assert!(has_auth_function_ref_v1(account_id), EAuthenticatorFunctionRefV1NotAttached); dynamic_field::borrow(account_id, auth_function_ref_v1_key()) }

Function has_auth_function_ref_v1

Check if an authenticator is attached. If a dynamic field with the AuthenticatorFunctionRefV1Key name exists.

public fun has_auth_function_ref_v1(account_id: &iota::object::UID): bool

Implementation

public fun has_auth_function_ref_v1(account_id: &UID): bool { dynamic_field::exists_(account_id, auth_function_ref_v1_key()) }

Function auth_function_ref_v1_key

fun auth_function_ref_v1_key(): iota::account::AuthenticatorFunctionRefV1Key

Implementation

Function attach_auth_function_ref_v1

Add authenticator as a dynamic field to account.

IMPORTANT: This function is allowed to be called only by the functions that the IOTA Move bytecode verifier prevents from being invoked outside the module where Account is declared.

fun attach_auth_function_ref_v1<Account: key>(account: &mut Account, authenticator: iota::authenticator_function::AuthenticatorFunctionRefV1<Account>)

Implementation

fun attach_auth_function_ref_v1<Account: key>( account: &mut Account, authenticator: AuthenticatorFunctionRefV1<Account>, ) { let account_id = borrow_account_uid_mut(account); assert!(!has_auth_function_ref_v1(account_id), EAuthenticatorFunctionRefV1AlreadyAttached); dynamic_field::add(account_id, auth_function_ref_v1_key(), authenticator); }

Function borrow_account_uid_mut

Borrow the account UID mutably.

IMPORTANT: This function is allowed to be called only by the functions that the IOTA Move bytecode verifier prevents from being invoked outside the module where Account is declared.

fun borrow_account_uid_mut<Account: key>(account: &mut Account): &mut iota::object::UID

Implementation

native fun borrow_account_uid_mut<Account: key>(account: &mut Account): &mut UID;

Function create_account_v1_impl

Turn account into a mutable shared object.

IMPORTANT: This function is allowed to be called only by the functions that the IOTA Move bytecode verifier prevents from being invoked outside the module where Account is declared.

fun create_account_v1_impl<Account: key>(account: Account)

Implementation

native fun create_account_v1_impl<Account: key>(account: Account);

Function create_immutable_account_v1_impl

Turn account into an immutable object.

IMPORTANT: This function is allowed to be called only by the functions that the IOTA Move bytecode verifier prevents from being invoked outside the module where Account is declared.

fun create_immutable_account_v1_impl<Account: key>(account: Account)

Implementation

native fun create_immutable_account_v1_impl<Account: key>(account: Account);