-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.gno
54 lines (43 loc) · 1.05 KB
/
helpers.gno
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
53
54
package shiken
import (
"std"
"strconv"
leaderboard "gno.land/p/dev/shiken_leaderboards"
)
func verifyAddressBelongsToDAO(caller std.Address) bool {
_, ok := DAO.Get(caller.String())
breakIfNotOk(ok, ErrNotDAOMember)
return true
}
func getProblemScoreTreeById(problemId int) *leaderboard.BTree {
treeInterface, ok := leaderboardsKeyToScore.Get(getStringFromInt(problemId))
breakIfNotOk(ok, ErrNoProblemId)
return treeInterface.(*leaderboard.BTree)
}
func getProblemById(problemId int) *leaderboard.BTree {
treeInterface, ok := Problems.Get(getStringFromInt(problemId))
breakIfNotOk(ok, ErrNoProblemId)
return treeInterface.(*leaderboard.BTree)
}
func getStringProblemId() string {
return strconv.Itoa(ProblemId)
}
func getStringFromInt(value int) string {
return strconv.Itoa(value)
}
func breakIfNotOk(ok bool, msg string) {
if !ok {
panic(msg)
}
}
func breakIfError(err error, msg string) {
if err != nil {
panic(msg)
}
}
func stringNotEmpty(value string) bool {
return len(value) != 0
}
func intNotZero(value int) bool {
return value != 0
}