Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

fishptr.gno

0.58 Kb · 42 lines
 1package fishptr
 2
 3const capFish = 128
 4
 5type fish struct {
 6	owner address
 7	name  string
 8	bite  int
 9	on    bool
10}
11
12var (
13	minted int
14	roster [capFish + 1]fish
15)
16
17func Version() string { return "ptr-1" }
18
19func mustFish(id int) *fish {
20	if id < 1 || id > minted {
21		panic("fish")
22	}
23	return &roster[id]
24}
25
26func NameOf(id int) string { return mustFish(id).name }
27
28func Mark(id int) {
29	row := mustFish(id)
30	row.on = true
31	row.bite = 24
32}
33
34func Plant(caller address) int {
35	if minted >= capFish {
36		panic("full")
37	}
38	minted++
39	roster[minted].owner = caller
40	roster[minted].name = "Bubble"
41	return minted
42}