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

directory.gno

1.13 Kb · 46 lines
 1package kourtv3
 2import "strconv"
 3const (
 4	tierHidden   uint8 = 0
 5	tierListed   uint8 = 1
 6	tierFeatured uint8 = 2
 7)
 8var directoryAdmin address
 9func SetTier(cur realm, courtSlug string, tier int) {
10	if !cur.IsCurrent() {
11		panic(errStaleRealm)
12	}
13	who := cur.Previous().Address()
14	if !isGlobalMod(who) {
15		panic("kourtv3: only a global DAO member may set a court's tier")
16	}
17	if tier < int(tierHidden) || tier > int(tierFeatured) {
18		panic("kourtv3: tier is 0 (hidden), 1 (listed), or 2 (featured)")
19	}
20	c := mustCourt(courtSlug)
21	if c.tier == uint8(tier) {
22		return
23	}
24	c.tier = uint8(tier)
25	emitGlobalAct(c.id, 0, "tier:"+strconv.Itoa(tier), who)
26}
27func DirectoryAdmin() address        { return directoryAdmin }
28func CourtTier(courtSlug string) int { return int(mustCourt(courtSlug).tier) }
29func ListCourts() []string {
30	out := []string{}
31	courts.Iterate("", "", func(key string, _ any) bool {
32		out = append(out, key)
33		return false
34	})
35	return out
36}
37func ListByTier(tier int) []string {
38	out := []string{}
39	courts.Iterate("", "", func(key string, v any) bool {
40		if int(v.(*Court).tier) == tier {
41			out = append(out, key)
42		}
43		return false
44	})
45	return out
46}