Skip to content

Latest commit

 

History

History
532 lines (241 loc) · 17.1 KB

account.md

File metadata and controls

532 lines (241 loc) · 17.1 KB

Module 0x2::account

Resource Account

Account is part of the StorageAbstraction It is also used to store the account's resources

struct Account has key

Resource ResourceAccount

ResourceAccount can only be stored under address, not in other structs.

struct ResourceAccount has key

Struct SignerCapability

SignerCapability can only be stored in other structs, not under address. So that the capability is always controlled by contracts, not by some EOA.

struct SignerCapability has store

Constants

const MAX_U64: u128 = 18446744073709551615;

const CONTRACT_ACCOUNT_AUTH_KEY_PLACEHOLDER: vector<u8> = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];

Account already exists

const ErrorAccountAlreadyExists: u64 = 1;

Resource Account can't derive resource account

Account does not exists

const ErrorAccountNotExists: u64 = 2;

Cannot create account because address is reserved

const ErrorAddressReserved: u64 = 4;

Address to create is not a valid reserved address

An attempt to create a resource account on an account that has a committed transaction

The resource with the given type already exists

The resource with the given type not exists

const ErrorResourceNotExists: u64 = 9;

Sequence number exceeds the maximum value for a u64

const ErrorSequenceNumberTooBig: u64 = 3;

Scheme identifier used when hashing an account's address together with a seed to derive the address (not the authentication key) of a resource account. This is an abuse of the notion of a scheme identifier which, for now, serves to domain separate hashes used to derive resource account addresses from hashes used to derive authentication keys. Without such separation, an adversary could create (and get a signer for) a resource account whose address matches an existing address of a MultiEd25519 wallet.

const ZERO_AUTH_KEY: vector<u8> = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

Function create_account_by_system

Publishes a new Account resource under new_address via system. A signer representing new_address is returned. This way, the caller of this function can publish additional resources under new_address.

public fun create_account_by_system(system: &signer, new_address: address): signer

Function create_system_reserved_account

create the account for system reserved addresses

Function sequence_number

Return the current sequence number at addr

public fun sequence_number(addr: address): u64

Function increment_sequence_number_for_system

public fun increment_sequence_number_for_system(system: &signer, sender: address)

Function signer_address

public fun signer_address(cap: &account::SignerCapability): address

Function is_resource_account

public fun is_resource_account(addr: address): bool

Function exists_at

public fun exists_at(addr: address): bool

Function create_signer_for_system

public fun create_signer_for_system(system: &signer, addr: address): signer

Function create_signer

public(friend) fun create_signer(addr: address): signer

Function create_resource_account

A resource account is used to manage resources independent of an account managed by a user. In Rooch a resource account is created based upon the sha3 256 of the source's address and additional seed data. A resource account can only be created once

Function create_signer_with_capability

Function get_signer_capability_address

public fun get_signer_capability_address(capability: &account::SignerCapability): address

Function account_object_id

Function create_account_object

Create a new account object space

public(friend) fun create_account_object(account: address)

Function account_borrow_resource

Function account_borrow_mut_resource

public fun account_borrow_mut_resource<T: key>(self: &mut object::Object<account::Account>): &mut T

Function account_move_resource_to

public fun account_move_resource_to<T: key>(self: &mut object::Object<account::Account>, resource: T)

Function account_move_resource_from

public fun account_move_resource_from<T: key>(self: &mut object::Object<account::Account>): T

Function account_exists_resource

public fun account_exists_resource<T: key>(self: &object::Object<account::Account>): bool

Function transfer

public(friend) fun transfer(obj: object::Object<account::Account>, account: address)

Function borrow_account

Function borrow_resource

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

Function borrow_mut_resource

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

Function move_resource_to

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)

Function move_resource_from

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

Function exists_resource

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