- Struct
Balance
- Resource
CoinStore
- Struct
CreateEvent
- Struct
DepositEvent
- Struct
WithdrawEvent
- Struct
FreezeEvent
- Struct
RemoveEvent
- Constants
- Function
create_coin_store
- Function
create_coin_store_extend
- Function
remove_coin_store
- Function
balance
- Function
is_frozen
- Function
withdraw
- Function
withdraw_extend
- Function
deposit
- Function
deposit_extend
- Function
transfer
- Function
borrow_mut_coin_store_extend
- Function
freeze_coin_store_extend
- Function
create_coin_store_internal
- Function
create_account_coin_store
- Function
borrow_mut_coin_store_internal
- Function
withdraw_internal
- Function
deposit_internal
use 0x1::string;
use 0x2::event;
use 0x2::object;
use 0x2::type_info;
use 0x3::coin;
The Balance resource that stores the balance of a specific coin type.
struct Balance has store
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
Event emitted when a coin store is created.
struct CreateEvent has copy, drop, store
Event emitted when some amount of a coin is deposited into a coin store.
struct DepositEvent has copy, drop, store
Event emitted when some amount of a coin is withdrawn from a coin store.
struct WithdrawEvent has copy, drop, store
Event emitted when a coin store is frozen or unfrozen.
struct FreezeEvent has copy, drop, store
Event emitted when a coin store is removed.
struct RemoveEvent has copy, drop, store
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
const ErrorCoinStoreTransferNotSupported: u64 = 5;
The CoinType parameter and CoinType in CoinStore do not match
const ErrorCoinTypeAndStoreMismatch: u64 = 3;
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>>
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>>
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>
public fun balance<CoinType: key>(coin_store_obj: &object::Object<coin_store::CoinStore<CoinType>>): u256
public fun is_frozen<CoinType: key>(coin_store_obj: &object::Object<coin_store::CoinStore<CoinType>>): bool
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>
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>
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>)
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>)
public fun transfer<CoinType: key>(_coin_store_obj: object::Object<coin_store::CoinStore<CoinType>>, _owner: address)
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>>
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)
public(friend) fun create_coin_store_internal<CoinType: key>(): object::Object<coin_store::CoinStore<CoinType>>
public(friend) fun create_account_coin_store<CoinType: key>(account: address): object::ObjectID
public(friend) fun borrow_mut_coin_store_internal<CoinType: key>(object_id: object::ObjectID): &mut object::Object<coin_store::CoinStore<CoinType>>
public(friend) fun withdraw_internal<CoinType: key>(coin_store_obj: &mut object::Object<coin_store::CoinStore<CoinType>>, amount: u256): coin::Coin<CoinType>
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>)