utils.gno
0.97 Kb ยท 52 lines
1package block
2
3import (
4 "strconv"
5
6 "gno.land/p/demo/tokens/grc1155"
7 "gno.land/p/nt/ufmt"
8
9 "gno.land/r/akkadia/admin"
10)
11
12func getAdmin() address {
13 return admin.GetAdmin()
14}
15
16func assertIsAdmin(address address) {
17 if address != getAdmin() {
18 panic("admin access required")
19 }
20}
21
22func parseAddress(str string) address {
23 addr := address(str)
24 if !addr.IsValid() {
25 panic("invalid address: " + str)
26 }
27 return addr
28}
29
30func blockIDToKey(blockID uint32) string {
31 s := strconv.FormatUint(uint64(blockID), 10)
32 // Pad to 10 digits for proper AVL tree sorting
33 for len(s) < 10 {
34 s = "0" + s
35 }
36 return s
37}
38
39func blockIDToString(blockID uint32) string {
40 return ufmt.Sprintf("%d", blockID)
41}
42
43func stringToBlockID(blockIDStr string) uint32 {
44 value, err := strconv.ParseUint(blockIDStr, 10, 32)
45 if err != nil {
46 panic("invalid blockID: " + err.Error())
47 }
48 return uint32(value)
49}
50
51func blockIDToTokenID(blockID uint32) grc1155.TokenID {
52 return grc1155.TokenID(blockIDToString(blockID))
53}