Search Apps Documentation Source Content File Folder Download Copy Actions Download

util.gno

0.88 Kb · 49 lines
 1package grc721
 2
 3const (
 4	MaxNameLen   = 64
 5	MaxSymbolLen = 11
 6)
 7
 8var zeroAddress = address("")
 9
10func isValidAddress(addr address) error {
11	if !addr.IsValid() {
12		return ErrInvalidAddress
13	}
14	return nil
15}
16
17func validName(name string) bool {
18	if name == "" || len(name) > MaxNameLen {
19		return false
20	}
21	for _, c := range name {
22		if c < 0x20 || c == 0x7f {
23			return false
24		}
25	}
26	return true
27}
28
29// symbol is emitted as part of the event identifier, so bounding it
30// keeps events under MaxEventAttrLen.
31func validSymbol(symbol string) bool {
32	if symbol == "" || len(symbol) > MaxSymbolLen {
33		return false
34	}
35	for _, c := range symbol {
36		if !isAlnum(c) && c != '_' && c != '-' {
37			return false
38		}
39	}
40	return true
41}
42
43func isAlnum(c rune) bool {
44	return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
45}
46
47func emit(event any) {
48	// TODO: setup a pubsub system here?
49}