hof.gno
2.06 Kb · 77 lines
1package acr
2
3import (
4 "chain"
5
6 "gno.land/p/akkadia/v0/accesscontrol"
7 "gno.land/r/akkadia/v0/admin"
8)
9
10const (
11 CreateHofCategoryEvent = "CreateHofCategory"
12 RemoveHofCategoryEvent = "RemoveHofCategory"
13 SetHofEntriesEvent = "SetHofEntries"
14)
15
16// ==================== Admin or Operator Functions ====================
17
18// CreateHofCategory creates a new Hall of Fame category
19func CreateHofCategory(cur realm, name string) {
20 assertNotFrozen()
21 caller := accesscontrol.MustGetAdminOrOperatorCaller(0, cur, admin.IsAdmin, admin.IsOperator)
22 validateHofCategoryName(name)
23 acrStore.CreateHofCategory(name)
24
25 chain.Emit(
26 CreateHofCategoryEvent,
27 "caller", caller.String(),
28 "name", name,
29 )
30}
31
32// RemoveHofCategory removes a Hall of Fame category and all its entries
33func RemoveHofCategory(cur realm, name string) {
34 assertNotFrozen()
35 caller := accesscontrol.MustGetAdminOrOperatorCaller(0, cur, admin.IsAdmin, admin.IsOperator)
36 acrStore.RemoveHofCategory(name)
37
38 chain.Emit(
39 RemoveHofCategoryEvent,
40 "caller", caller.String(),
41 "name", name,
42 )
43}
44
45// SetHofEntries sets the entire CSV data for a Hall of Fame category (header included)
46func SetHofEntries(cur realm, category string, csvRows string) {
47 assertNotFrozen()
48 caller := accesscontrol.MustGetAdminOrOperatorCaller(0, cur, admin.IsAdmin, admin.IsOperator)
49 validatedRows := validateHofEntries(csvRows)
50 acrStore.SetHofEntries(category, validatedRows)
51
52 chain.Emit(
53 SetHofEntriesEvent,
54 "caller", caller.String(),
55 "category", category,
56 )
57}
58
59// ==================== Query Functions ====================
60
61// ListHofCategories returns paginated Hall of Fame category names
62func ListHofCategories(page int, count int) []string {
63 assertMigrationStateAvailable()
64 assertListPageCount(page, count)
65 return acrStore.ListHofCategories(page, count)
66}
67
68func GetHofCategorySize() int {
69 assertMigrationStateAvailable()
70 return acrStore.HofCategoryCount()
71}
72
73// GetHofEntries returns the CSV string for a Hall of Fame category
74func GetHofEntries(category string) string {
75 assertMigrationStateAvailable()
76 return acrStore.GetHofEntries(category)
77}