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

records.gno

1.36 Kb · 52 lines
 1package kourtv3
 2type answerRecord struct {
 3	score          int
 4	activePriority uint64
 5}
 6func creditUpheld(c *Court, who address) {
 7	r := getRecord(c, who)
 8	wasQualified := r.score >= priorityNetRecord
 9	r.score++
10	if !wasQualified && r.score >= priorityNetRecord {
11		c.qualifiedCount++
12	}
13}
14func resetOverturned(c *Court, who address) {
15	r := getRecord(c, who)
16	if r.score >= priorityNetRecord {
17		c.qualifiedCount--
18	}
19	r.score = 0
20}
21func priorityGateActive(c *Court) bool { return c.qualifiedCount >= priorityColdStartN }
22func mayAnswerInPriority(c *Court, who address) bool {
23	r := getRecord(c, who)
24	return r.score >= priorityNetRecord && r.activePriority == 0
25}
26func holdPriority(c *Court, who address, claimID uint64) {
27	getRecord(c, who).activePriority = claimID
28}
29func releasePriority(c *Court, who address, claimID uint64) {
30	r := getRecord(c, who)
31	if r.activePriority == claimID {
32		r.activePriority = 0
33	}
34}
35func getRecord(c *Court, who address) *answerRecord {
36	if v := c.records.Get(string(who)); v != nil {
37		return v.(*answerRecord)
38	}
39	r := &answerRecord{}
40	c.records.Set(string(who), r)
41	return r
42}
43func AnswerRecord(courtSlug string, who address) int {
44	c := mustCourt(courtSlug)
45	if v := c.records.Get(string(who)); v != nil {
46		return v.(*answerRecord).score
47	}
48	return 0
49}
50func PriorityGateActive(courtSlug string) bool {
51	return priorityGateActive(mustCourt(courtSlug))
52}