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

governance_reads.gno

1.36 Kb · 47 lines
 1package memba_appstore_v3
 2
 3import (
 4	"crypto/sha256"
 5	"encoding/hex"
 6	"strings"
 7)
 8
 9func IsPaused() bool        { return paused }
10func IsSeedingSealed() bool { return seedingSealed }
11
12// Scalars only: no persistent Listing pointer or screenshot slice escapes.
13type GovernanceListing struct {
14	Exists                      bool
15	ContentHash, Status, Reason string
16	Credit                      bool
17	Flags                       int
18	ClearKeys                   string
19}
20
21func GetGovernanceListing(pkgPath string, clearBatch bool) GovernanceListing {
22	v, ok := listings.Get(pkgPath)
23	if !ok {
24		return GovernanceListing{}
25	}
26	l := v.(*Listing)
27	snapshot := *l
28	snapshot.Status = ""
29	snapshot.RejectReason = ""
30	snapshot.PaidResubmitCredit = false
31	snapshot.FlagCount = 0
32	digest := sha256.Sum256([]byte(listingJSON(&snapshot, true)))
33	s := GovernanceListing{Exists: true, ContentHash: hex.EncodeToString(digest[:]), Status: l.Status, Reason: l.RejectReason, Credit: l.PaidResubmitCredit, Flags: l.FlagCount}
34	if clearBatch {
35		keys := []string{}
36		flaggedBy.Iterate(pkgPath+"\x00", pkgPath+"\x01", func(k string, _ any) bool {
37			keys = append(keys, strings.TrimPrefix(k, pkgPath+"\x00"))
38			return len(keys) >= MaxClearBatch
39		})
40		s.ClearKeys = strings.Join(keys, ",")
41	}
42	return s
43}
44func HasGovernanceFlag(pkgPath, who string) bool {
45	_, ok := flaggedBy.Get(pkgPath + "\x00" + who)
46	return ok
47}