-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.sw
More file actions
52 lines (46 loc) · 1.14 KB
/
main.sw
File metadata and controls
52 lines (46 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
contract;
// use string::String;
use std::address::Address;
use std::constants::ZERO_B256;
use std::token::mint_to_address;
use std::bytes::Bytes;
configurable {
DECIMALS: u8 = 9,
NAME: str[32] = " ",
SYMBOL: str[8] = " ",
OWNER: Address = Address::from(ZERO_B256),
MINT_AMOUNT: u64 = 0,
}
storage {
total_supply: u64 = 0u64,
}
abi FRC20 {
#[storage(read)]
fn total_supply() -> u64;
fn decimals() -> u8;
fn name() -> str[32];
fn symbol() -> str[8];
#[storage(read, write)]
fn _mint(amount: u64, recipient: Address);
}
impl FRC20 for Contract {
#[storage(read)]
fn total_supply() -> u64 {
storage.total_supply.read()
}
fn decimals() -> u8 {
DECIMALS
}
fn name() -> str[32] {
NAME
}
fn symbol() -> str[8] {
SYMBOL
}
#[storage(read, write)]
fn _mint(amount: u64, recipient: Address){
assert(msg_sender().unwrap() == Identity::Address(OWNER));
storage.total_supply.write(storage.total_supply.try_read().unwrap_or(0) + 1);
mint_to_address(amount, recipient);
}
}