- Resource
Account
- Constants
- Function
create_account_by_system
- Function
create_account
- Function
sequence_number
- Function
increment_sequence_number_for_system
- Function
exists_at
- Function
create_signer_for_system
- Function
create_signer_with_account
- Function
account_object_id
- Function
account_borrow_resource
- Function
account_borrow_mut_resource
- Function
account_move_resource_to
- Function
account_move_resource_from
- Function
account_exists_resource
- Function
destroy_account
- Function
borrow_account
- Function
borrow_mut_account
- Function
borrow_resource
- Function
borrow_mut_resource
- Function
move_resource_to
- Function
move_resource_from
- Function
exists_resource
use 0x1::signer;
use 0x1::string;
use 0x2::core_addresses;
use 0x2::object;
use 0x2::tx_context;
use 0x2::type_table;
Account is part of the StorageAbstraction It is also used to store the account's resources
struct Account has key
const MAX_U64: u128 = 18446744073709551615;
Account already exists
const ErrorAccountAlreadyExists: u64 = 1;
Cannot create account because address is reserved
const ErrorAddressReserved: u64 = 3;
Address to create is not a valid reserved address
const ErrorNotValidSystemReservedAddress: u64 = 4;
The resource with the given type already exists
const ErrorResourceAlreadyExists: u64 = 5;
The resource with the given type not exists
const ErrorResourceNotExists: u64 = 6;
Sequence number exceeds the maximum value for a u64
const ErrorSequenceNumberTooBig: u64 = 2;
Create a new account for the given address, only callable by the system account
public fun create_account_by_system(system: &signer, new_address: address): signer
Create an Account Object with a generated address
public fun create_account(): object::Object<account::Account>
Return the current sequence number at addr
public fun sequence_number(addr: address): u64
public fun increment_sequence_number_for_system(system: &signer, sender: address)
public fun exists_at(addr: address): bool
public fun create_signer_for_system(system: &signer, addr: address): signer
Create a signer with mutable Object
public fun create_signer_with_account(account: &mut object::Object<account::Account>): signer
public fun account_object_id(account: address): object::ObjectID
public fun account_borrow_resource<T: key>(self: &object::Object<account::Account>): &T
#[private_generics(#[T])]
public fun account_borrow_mut_resource<T: key>(self: &mut object::Object<account::Account>): &mut T
#[private_generics(#[T])]
public fun account_move_resource_to<T: key>(self: &mut object::Object<account::Account>, resource: T)
#[private_generics(#[T])]
public fun account_move_resource_from<T: key>(self: &mut object::Object<account::Account>): T
public fun account_exists_resource<T: key>(self: &object::Object<account::Account>): bool
Destroy the account object
public fun destroy_account(account_obj: object::Object<account::Account>)
public fun borrow_account(account: address): &object::Object<account::Account>
public fun borrow_mut_account(account: &signer): &mut object::Object<account::Account>
Borrow a resource from the account's storage
This function equates to borrow_global<T>(address)
instruction in Move
But we remove the restriction of the caller must be the module of T
public fun borrow_resource<T: key>(account: address): &T
Borrow a mut resource from the account's storage
This function equates to borrow_global_mut<T>(address)
instruction in Move
#[private_generics(#[T])]
public fun borrow_mut_resource<T: key>(account: address): &mut T
Move a resource to the account's resource object
This function equates to move_to<T>(&signer, resource)
instruction in Move
#[private_generics(#[T])]
public fun move_resource_to<T: key>(account: &signer, resource: T)
Move a resource from the account's storage
This function equates to move_from<T>(address)
instruction in Move
#[private_generics(#[T])]
public fun move_resource_from<T: key>(account: address): T
Check if the account has a resource of the given type
This function equates to exists<T>(address)
instruction in Move
But we remove the restriction of the caller must be the module of T
public fun exists_resource<T: key>(account: address): bool