- Resource
Account
- Resource
ResourceAccount
- Struct
SignerCapability
- Constants
- Function
create_account_by_system
- Function
create_system_reserved_account
- Function
sequence_number
- Function
increment_sequence_number_for_system
- Function
signer_address
- Function
is_resource_account
- Function
exists_at
- Function
create_signer_for_system
- Function
create_signer
- Function
create_resource_account
- Function
create_signer_with_capability
- Function
get_signer_capability_address
- Function
account_object_id
- Function
create_account_object
- Function
account_borrow_resource
- Function
account_borrow_mut_resource
- Function
account_move_resource_to
- Function
account_move_resource_from
- Function
account_exists_resource
- Function
transfer
- Function
borrow_account
- Function
borrow_resource
- Function
borrow_mut_resource
- Function
move_resource_to
- Function
move_resource_from
- Function
exists_resource
use 0x1::ascii;
use 0x1::hash;
use 0x1::signer;
use 0x1::vector;
use 0x2::bcs;
use 0x2::core_addresses;
use 0x2::object;
use 0x2::type_table;
Account is part of the StorageAbstraction It is also used to store the account's resources
struct Account has key
ResourceAccount can only be stored under address, not in other structs.
struct ResourceAccount has key
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
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
const ErrorAccountIsAlreadyResourceAccount: u64 = 6;
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
const ErrorNotValidSystemReservedAddress: u64 = 7;
An attempt to create a resource account on an account that has a committed transaction
const ErrorResourceAccountAlreadyUsed: u64 = 5;
The resource with the given type already exists
const ErrorResourceAlreadyExists: u64 = 8;
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 SCHEME_DERIVE_RESOURCE_ACCOUNT: u8 = 255;
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];
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
create the account for system reserved addresses
public fun create_system_reserved_account(system: &signer, addr: address): (signer, account::SignerCapability)
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 signer_address(cap: &account::SignerCapability): address
public fun is_resource_account(addr: address): bool
public fun exists_at(addr: address): bool
public fun create_signer_for_system(system: &signer, addr: address): signer
public(friend) fun create_signer(addr: address): signer
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
public fun create_resource_account(source: &signer): (signer, account::SignerCapability)
public fun create_signer_with_capability(capability: &account::SignerCapability): signer
public fun get_signer_capability_address(capability: &account::SignerCapability): address
public fun account_object_id(account: address): object::ObjectID
Create a new account object space
public(friend) fun create_account_object(account: address)
public fun account_borrow_resource<T: key>(self: &object::Object<account::Account>): &T
public fun account_borrow_mut_resource<T: key>(self: &mut object::Object<account::Account>): &mut T
public fun account_move_resource_to<T: key>(self: &mut object::Object<account::Account>, resource: 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
public(friend) fun transfer(obj: object::Object<account::Account>, account: address)
public fun borrow_account(account: address): &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