fatgnot.gno
1.51 Kb · 57 lines
1package fatgnot
2
3var (
4 owner string = "g1pd2jqrgc0hwsx3evqk8lakvz7y89zkx4nc78g0"
5 name string = "Fat Gno.Land"
6 symbol string = "FATGNOT"
7 decimals uint8 = 6
8 totalSupply uint64 = 1000000000000
9 balances = make(map[string]uint64)
10 allowances = make(map[string]map[string]uint64)
11)
12
13func init() {
14 balances[owner] = totalSupply
15}
16
17func Name() string { return name }
18func Symbol() string { return symbol }
19func Decimals() uint8 { return decimals }
20func TotalSupply() uint64 { return totalSupply }
21func BalanceOf(account string) uint64 { return balances[account] }
22
23func Allowance(ownerAddr, spender string) uint64 {
24 if allocs, ok := allowances[ownerAddr]; ok {
25 return allocs[spender]
26 }
27 return 0
28}
29
30func Transfer(caller, to string, amount uint64) string {
31 if balances[caller] < amount {
32 panic("insufficient balance")
33 }
34 balances[caller] -= amount
35 balances[to] += amount
36 return "Transfer successful"
37}
38
39func Approve(caller, spender string, amount uint64) string {
40 if allowances[caller] == nil {
41 allowances[caller] = make(map[string]uint64)
42 }
43 allowances[caller][spender] = amount
44 return "Approve successful"
45}
46
47func TransferFrom(caller, from, to string, amount uint64) string {
48 if allowances[from][caller] < amount {
49 panic("insufficient allowance")
50 }
51 if balances[from] < amount {
52 panic("insufficient balance")
53 }
54 allowances[from][caller] -= amount
55 balances[from] -= amount
56 balances[to] += amount
57 return "TransferFrom successful"
58}