Module 0x2::iota
Coin<IOTA>
is the token used to pay for gas in IOTA.
It has 9 decimals, and the smallest unit (10^-9) is called "nano".
- Struct
IOTA
- Struct
IotaTreasuryCap
- Constants
- Function
new
- Function
transfer
- Function
mint
- Function
mint_balance
- Function
burn
- Function
burn_balance
- Function
total_supply
use 0x1::option;
use 0x2::balance;
use 0x2::coin;
use 0x2::transfer;
use 0x2::tx_context;
use 0x2::url;
Struct IOTA
Name of the coin
struct IOTA has drop
Fields
dummy_field: bool
Struct IotaTreasuryCap
The IOTA token treasury capability. Protects the token from unauthorized changes.
struct IotaTreasuryCap has store
Fields
inner: coin::TreasuryCap<iota::IOTA>
Constants
Sender is not @0x0 the system address.
const ENotSystemAddress: u64 = 1;
const EAlreadyMinted: u64 = 0;
Function new
Register the IOTA
Coin to acquire IotaTreasuryCap
.
This should be called only once during genesis creation.
fun new(ctx: &mut tx_context::TxContext): iota::IotaTreasuryCap
Implementation
fun new(ctx: &mut TxContext): IotaTreasuryCap {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
assert!(ctx.epoch() == 0, EAlreadyMinted);
let (treasury, metadata) = coin::create_currency(
IOTA {},
9,
b"IOTA",
b"IOTA",
b"The main (gas)token of the IOTA Network.",
option::some(url::new_unsafe_from_bytes(b"https://iota.org/logo.png")),
ctx
);
transfer::public_freeze_object(metadata);
IotaTreasuryCap {
inner: treasury,
}
}
Function transfer
public entry fun transfer(c: coin::Coin<iota::IOTA>, recipient: address)
Implementation
public entry fun transfer(c: coin::Coin<IOTA>, recipient: address) {
transfer::public_transfer(c, recipient)
}
Function mint
Create an IOTA coin worth value
and increase the total supply in cap
accordingly.
public fun mint(cap: &mut iota::IotaTreasuryCap, value: u64, ctx: &mut tx_context::TxContext): coin::Coin<iota::IOTA>
Implementation
public fun mint(cap: &mut IotaTreasuryCap, value: u64, ctx: &mut TxContext): Coin<IOTA> {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
cap.inner.mint(value, ctx)
}
Function mint_balance
Mint some amount of IOTA as a Balance
and increase the total supply in cap
accordingly.
Aborts if value
+ cap.inner.total_supply
>= U64_MAX
public fun mint_balance(cap: &mut iota::IotaTreasuryCap, value: u64, ctx: &tx_context::TxContext): balance::Balance<iota::IOTA>
Implementation
public fun mint_balance(cap: &mut IotaTreasuryCap, value: u64, ctx: &TxContext): Balance<IOTA> {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
cap.inner.mint_balance(value)
}
Function burn
Destroy the IOTA coin c
and decrease the total supply in cap
accordingly.
public fun burn(cap: &mut iota::IotaTreasuryCap, c: coin::Coin<iota::IOTA>, ctx: &tx_context::TxContext): u64
Implementation
public fun burn(cap: &mut IotaTreasuryCap, c: Coin<IOTA>, ctx: &TxContext): u64 {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
cap.inner.burn(c)
}
Function burn_balance
Destroy the IOTA balance b
and decrease the total supply in cap
accordingly.
public fun burn_balance(cap: &mut iota::IotaTreasuryCap, b: balance::Balance<iota::IOTA>, ctx: &tx_context::TxContext): u64
Implementation
public fun burn_balance(cap: &mut IotaTreasuryCap, b: Balance<IOTA>, ctx: &TxContext): u64 {
assert!(ctx.sender() == @0x0, ENotSystemAddress);
cap.inner.supply_mut().decrease_supply(b)
}
Function total_supply
Return the total number of IOTA's in circulation.
public fun total_supply(cap: &iota::IotaTreasuryCap): u64
Implementation
public fun total_supply(cap: &IotaTreasuryCap): u64 {
cap.inner.total_supply()
}