Skip to content

Latest commit

 

History

History
306 lines (150 loc) · 10.9 KB

account_coin_store.md

File metadata and controls

306 lines (150 loc) · 10.9 KB

Module 0x3::account_coin_store

Resource AutoAcceptCoins

A resource that holds the AutoAcceptCoin config for all accounts. The main scenario is that the user can actively turn off the AutoAcceptCoin setting to avoid automatically receiving Coin

struct AutoAcceptCoins has store, key

Struct AcceptCoinEvent

Event for auto accept coin set

struct AcceptCoinEvent has copy, drop, store

Constants

Account hasn't accept CoinType

const ErrorAccountNotAcceptCoin: u64 = 1;

Function genesis_init

public(friend) fun genesis_init(genesis_account: &signer)

Function balance

Returns the balance of addr for provided CoinType.

public fun balance<CoinType: key>(addr: address): u256

Function account_coin_store_id

Return the account CoinStore object id for addr the account CoinStore is a account named object, the id is determinate for each addr and CoinType

public fun account_coin_store_id<CoinType: key>(addr: address): object::ObjectID

Function is_accept_coin

Return whether the account at addr accept Coin type coins

public fun is_accept_coin<CoinType: key>(addr: address): bool

Function can_auto_accept_coin

Check whether the address can auto accept coin. Default is true if absent

public fun can_auto_accept_coin(addr: address): bool

Function do_accept_coin

Add a balance of Coin type to the sending account. If user turns off AutoAcceptCoin, call this method to receive the corresponding Coin

public fun do_accept_coin<CoinType: key>(account: &signer)

Function set_auto_accept_coin

Configure whether auto-accept coins.

public fun set_auto_accept_coin(account: &signer, enable: bool)

Function withdraw

Withdraw specified amount of coin CoinType from the signing account. This public entry function requires the CoinType to have key and store abilities.

public fun withdraw<CoinType: store, key>(account: &signer, amount: u256): coin::Coin<CoinType>

Function deposit

Deposit the coin into the recipient's account and emit an event. This public entry function requires the CoinType to have key and store abilities.

public fun deposit<CoinType: store, key>(addr: address, coin: coin::Coin<CoinType>)

Function transfer

Transfer amount of coins CoinType from from to to. Any account and module can call this function to transfer coins, the CoinType must have key and store abilities.

public fun transfer<CoinType: store, key>(from: &signer, to: address, amount: u256)

Function exist_account_coin_store

public fun exist_account_coin_store<CoinType: key>(addr: address): bool

Function is_account_coin_store_frozen

public fun is_account_coin_store_frozen<CoinType: key>(addr: address): bool

Function withdraw_extend

Withdraw specified amount of coin CoinType from any addr, this function does not check the Coin frozen attribute This function is only called by the CoinType module, for the developer to extend custom withdraw logic

#[private_generics(#[CoinType])]
public fun withdraw_extend<CoinType: key>(addr: address, amount: u256): coin::Coin<CoinType>

Function deposit_extend

Deposit the coin into the recipient's account and emit an event. This function is only called by the CoinType module, for the developer to extend custom deposit logic

#[private_generics(#[CoinType])]
public fun deposit_extend<CoinType: key>(addr: address, coin: coin::Coin<CoinType>)

Function transfer_extend

Transfer amount of coins CoinType from from to to. This function is only called by the CoinType module, for the developer to extend custom transfer logic

#[private_generics(#[CoinType])]
public fun transfer_extend<CoinType: key>(from: address, to: address, amount: u256)

Function accept_coin_entry

Creating a resource that stores balance of CoinType on user's account. Required if user wants to start accepting deposits of CoinType in his account.

public entry fun accept_coin_entry<CoinType: key>(account: &signer)

Function enable_auto_accept_coin_entry

Enable account's auto-accept-coin feature. The script function is reenterable.

Function disable_auto_accept_coin_entry

Disable account's auto-accept-coin feature. The script function is reenterable.