Module sui::balance
A storable handler for Balances in general. Is used in the Coin module to allow balance operations and can be used to implement custom coins with Supply and Balances.
use std::address;
use std::ascii;
use std::bcs;
use std::internal;
use std::option;
use std::string;
use std::type_name;
use std::u128;
use std::vector;
use sui::accumulator;
use sui::address;
use sui::dynamic_field;
use sui::funds_accumulator;
use sui::hex;
use sui::object;
use sui::party;
use sui::protocol_config;
use sui::transfer;
use sui::tx_context;
use sui::vec_map;
Struct Supply
A Supply of T. Used for minting and burning.
Wrapped into a TreasuryCap in the Coin module.
public struct Supply<phantom T> has store
Fields
- value: u64
Struct Balance
Storable balance - an inner struct of a Coin type.
Can be used to store coins which don't need the key ability.
public struct Balance<phantom T> has store
Fields
- value: u64
Constants
For when trying to destroy a non-zero balance.
const ENonZero: u64 = 0;
For when an overflow is happening on Supply operations.
const EOverflow: u64 = 1;
For when trying to withdraw more than there is.
const ENotEnough: u64 = 2;
Sender is not @0x0 the system address.
const ENotSystemAddress: u64 = 3;
System operation performed for a coin other than SUI
const ENotSUI: u64 = 4;
const SUI_TYPE_NAME: vector<u8> = vector[48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 58, 58, 115, 117, 105, 58, 58, 83, 85, 73];
Function value
Get the amount stored in a Balance.
public fun value<T>(self: &sui::balance::Balance<T>): u64
Function supply_value
Get the Supply value.
public fun supply_value<T>(supply: &sui::balance::Supply<T>): u64
Function create_supply
Create a new supply for type T.
public fun create_supply<T: drop>(_: T): sui::balance::Supply<T>
Function increase_supply
Increase supply by value and create a new Balance<T> with this value.
public fun increase_supply<T>(self: &mut sui::balance::Supply<T>, value: u64): sui::balance::Balance<T>