types.gno
2.51 Kb · 135 lines
1package quillbounty
2
3import (
4 "strconv"
5 "strings"
6)
7
8const (
9 DenomUgnot = "ugnot"
10 MinDurationBlocks = int64(10)
11 MaxDurationBlocks = int64(5_000_000)
12 MaxTitleLen = 120
13 MaxSpecLen = 4000
14 MaxSummaryLen = 1000
15 MaxURLLen = 300
16)
17
18type BountyStatus string
19
20const (
21 StatusOpen BountyStatus = "open"
22 StatusCompleted BountyStatus = "completed"
23 StatusExpired BountyStatus = "expired"
24)
25
26type SubmissionStatus string
27
28const (
29 SubPending SubmissionStatus = "pending"
30 SubNeedsRevision SubmissionStatus = "needs_revision"
31 SubApproved SubmissionStatus = "approved"
32)
33
34type Submission struct {
35 ID uint64
36 BountyID uint64
37 Builder address
38 ProofURL string
39 CommitHash string
40 Summary string
41 Status SubmissionStatus
42 ReviewNote string
43 PayoutUgnot int64
44 SubmittedAt int64
45 ReviewedAt int64
46}
47
48type Bounty struct {
49 ID uint64
50 Sponsor address
51 Reviewer address
52 Title string
53 Category string
54 Spec string
55 TotalFunded int64
56 RemainingUgnot int64
57 CreatedHeight int64
58 DeadlineHeight int64
59 Status BountyStatus
60 Submissions []*Submission
61}
62
63type BuilderProfile struct {
64 Address address
65 CompletedCount int
66 TotalEarnedUgnot int64
67 LastBountyID uint64
68}
69
70func padID(id uint64) string {
71 s := strconv.FormatUint(id, 10)
72 if len(s) >= 12 {
73 return s
74 }
75 return strings.Repeat("0", 12-len(s)) + s
76}
77
78func normalizeCategory(cat string) string {
79 c := strings.ToLower(strings.TrimSpace(cat))
80 switch c {
81 case "dev", "ai", "security", "docs", "design":
82 return c
83 default:
84 return "dev"
85 }
86}
87
88func formatGNOT(ugnot int64) string {
89 if ugnot < 0 {
90 return "-" + formatGNOT(-ugnot)
91 }
92 whole := ugnot / 1_000_000
93 frac := ugnot % 1_000_000
94 if frac == 0 {
95 return strconv.FormatInt(whole, 10) + " GNOT"
96 }
97 f := strconv.FormatInt(frac, 10)
98 f = strings.Repeat("0", 6-len(f)) + f
99 f = strings.TrimRight(f, "0")
100 return strconv.FormatInt(whole, 10) + "." + f + " GNOT"
101}
102
103func escapeJSON(s string) string {
104 var b strings.Builder
105 for i := 0; i < len(s); i++ {
106 c := s[i]
107 switch c {
108 case '"':
109 b.WriteString(`\"`)
110 case '\\':
111 b.WriteString(`\\`)
112 case '\n':
113 b.WriteString(`\n`)
114 case '\r':
115 b.WriteString(`\r`)
116 case '\t':
117 b.WriteString(`\t`)
118 default:
119 if c < 0x20 {
120 b.WriteString(" ")
121 } else {
122 b.WriteByte(c)
123 }
124 }
125 }
126 return b.String()
127}
128
129func shortAddr(a address) string {
130 s := a.String()
131 if len(s) <= 14 {
132 return s
133 }
134 return s[:8] + "..." + s[len(s)-4:]
135}