Skip to content

Latest commit

 

History

History
390 lines (182 loc) · 14.2 KB

coin_store.md

File metadata and controls

390 lines (182 loc) · 14.2 KB

Module 0x3::coin_store

Struct Balance

The Balance resource that stores the balance of a specific coin type.

struct Balance has store

Resource CoinStore

A holder of a specific coin types. These are kept in a single resource to ensure locality of data.

struct CoinStore<CoinType: key> has key

Struct CreateEvent

Event emitted when a coin store is created.

struct CreateEvent has copy, drop, store

Struct DepositEvent

Event emitted when some amount of a coin is deposited into a coin store.

struct DepositEvent has copy, drop, store

Struct WithdrawEvent

Event emitted when some amount of a coin is withdrawn from a coin store.

struct WithdrawEvent has copy, drop, store

Struct FreezeEvent

Event emitted when a coin store is frozen or unfrozen.

struct FreezeEvent has copy, drop, store

Struct RemoveEvent

Event emitted when a coin store is removed.

struct RemoveEvent has copy, drop, store

Constants

Not enough balance to withdraw from CoinStore

const ErrorInsufficientBalance: u64 = 4;

CoinStore is frozen. Coins cannot be deposited or withdrawn

const ErrorCoinStoreIsFrozen: u64 = 2;

The CoinStore is not found in the global object store

const ErrorCoinStoreNotFound: u64 = 1;

Transfer is not supported for CoinStore

The CoinType parameter and CoinType in CoinStore do not match

Function create_coin_store

Create a new CoinStore Object for CoinType and return the Object Anyone can create a CoinStore Object for public Coin, the CoinType must has key and store ability

public fun create_coin_store<CoinType: store, key>(): object::Object<coin_store::CoinStore<CoinType>>

Function create_coin_store_extend

This function is for the CoinType module to extend

#[private_generics(#[CoinType])]
public fun create_coin_store_extend<CoinType: key>(): object::Object<coin_store::CoinStore<CoinType>>

Function remove_coin_store

Remove the CoinStore Object, return the Coin in balance

public fun remove_coin_store<CoinType: key>(coin_store_object: object::Object<coin_store::CoinStore<CoinType>>): coin::Coin<CoinType>

Function balance

public fun balance<CoinType: key>(coin_store_obj: &object::Object<coin_store::CoinStore<CoinType>>): u256

Function is_frozen

public fun is_frozen<CoinType: key>(coin_store_obj: &object::Object<coin_store::CoinStore<CoinType>>): bool

Function withdraw

Withdraw amount Coin from the balance of the passed-in coin_store This function requires the CoinType must has key and store ability

public fun withdraw<CoinType: store, key>(coin_store_obj: &mut object::Object<coin_store::CoinStore<CoinType>>, amount: u256): coin::Coin<CoinType>

Function withdraw_extend

Withdraw amount Coin from the balance of the passed-in coin_store This function is for the CoinType module to extend

#[private_generics(#[CoinType])]
public fun withdraw_extend<CoinType: key>(coin_store_obj: &mut object::Object<coin_store::CoinStore<CoinType>>, amount: u256): coin::Coin<CoinType>

Function deposit

Deposit amount Coin to the balance of the passed-in coin_store This function requires the CoinType must has key and store ability

public fun deposit<CoinType: store, key>(coin_store_obj: &mut object::Object<coin_store::CoinStore<CoinType>>, coin: coin::Coin<CoinType>)

Function deposit_extend

Deposit amount Coin to the balance of the passed-in coin_store This function is for the CoinType module to extend

#[private_generics(#[CoinType])]
public fun deposit_extend<CoinType: key>(coin_store_obj: &mut object::Object<coin_store::CoinStore<CoinType>>, coin: coin::Coin<CoinType>)

Function transfer

public fun transfer<CoinType: key>(_coin_store_obj: object::Object<coin_store::CoinStore<CoinType>>, _owner: address)

Function borrow_mut_coin_store_extend

Borrow a mut CoinStore Object by the coin store id This function is for the CoinType module to extend

#[private_generics(#[CoinType])]
public fun borrow_mut_coin_store_extend<CoinType: key>(object_id: object::ObjectID): &mut object::Object<coin_store::CoinStore<CoinType>>

Function freeze_coin_store_extend

Freeze or Unfreeze a CoinStore to prevent withdraw and desposit This function is for he CoinType module to extend, Only the CoinType module can freeze or unfreeze a CoinStore by the coin store id

#[private_generics(#[CoinType])]
public fun freeze_coin_store_extend<CoinType: key>(coin_store_obj: &mut object::Object<coin_store::CoinStore<CoinType>>, frozen: bool)

Function create_coin_store_internal

public(friend) fun create_coin_store_internal<CoinType: key>(): object::Object<coin_store::CoinStore<CoinType>>

Function create_account_coin_store

public(friend) fun create_account_coin_store<CoinType: key>(account: address): object::ObjectID

Function borrow_mut_coin_store_internal

public(friend) fun borrow_mut_coin_store_internal<CoinType: key>(object_id: object::ObjectID): &mut object::Object<coin_store::CoinStore<CoinType>>

Function withdraw_internal

public(friend) fun withdraw_internal<CoinType: key>(coin_store_obj: &mut object::Object<coin_store::CoinStore<CoinType>>, amount: u256): coin::Coin<CoinType>

Function deposit_internal

Deposit amount Coin to the balance of the passed-in coin_store

public(friend) fun deposit_internal<CoinType: key>(coin_store_obj: &mut object::Object<coin_store::CoinStore<CoinType>>, coin: coin::Coin<CoinType>)