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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

validate.gno

1.27 Kb · 44 lines
 1package arena
 2
 3// The string rules below are what makes the hand-built JSON and the markdown
 4// of this realm safe: every string that is stored and later printed went
 5// through one of them, and none of them lets a quote, a backslash, a pipe, a
 6// bracket or a control character in. They are the rules of the game realm.
 7
 8const ticketLen = 64 // a SHA-256 in hex
 9
10// validTicket reports whether s is 64 lowercase hex characters, the SHA-256
11// of the secret a player's client keeps.
12func validTicket(s string) bool {
13	if len(s) != ticketLen {
14		return false
15	}
16	for i := 0; i < len(s); i++ {
17		c := s[i]
18		if !(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') {
19			return false
20		}
21	}
22	return true
23}
24
25// validAddress reports whether addr is a valid address in its canonical,
26// lowercase form.
27//
28// Bech32 can also be written in all capitals, and address.IsValid accepts
29// that. Bech32 does not allow mixing cases, so looking at the first character
30// is enough.
31func validAddress(addr address) bool {
32	return addr.IsValid() && addr[0] == 'g'
33}
34
35// indexOfAddr returns the index of addr in list, -1 when it is not there.
36// The lists of this realm hold at most 16 addresses.
37func indexOfAddr(list []address, addr address) int {
38	for i, a := range list {
39		if a == addr {
40			return i
41		}
42	}
43	return -1
44}