ids.gno
0.75 Kb · 32 lines
1package bolo
2
3import (
4 "strconv"
5
6 "gno.land/p/nt/seqid/v0"
7)
8
9// parseID returns the campaign ID s names, if s is canonical (API C9): the
10// decimal form of a positive ID — digits only, no sign, no leading zero, no
11// space. "042" names nothing, never campaign 42: one ID has one spelling, and so
12// one set of addresses (INV-18).
13func parseID(s string) (seqid.ID, bool) {
14 if len(s) == 0 || len(s) > 20 || s[0] == '0' {
15 return 0, false
16 }
17 for i := 0; i < len(s); i++ {
18 if s[i] < '0' || s[i] > '9' {
19 return 0, false
20 }
21 }
22 n, err := strconv.ParseUint(s, 10, 64)
23 if err != nil {
24 return 0, false
25 }
26 return seqid.ID(n), true
27}
28
29// idString is the canonical decimal form of id.
30func idString(id seqid.ID) string {
31 return strconv.FormatUint(uint64(id), 10)
32}