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

admin.gno

1.28 Kb · 57 lines
 1package cla
 2
 3import (
 4	"chain"
 5
 6	"gno.land/p/moul/addrset/v0"
 7	"gno.land/p/moul/helplink/v0"
 8	"gno.land/r/gov/dao"
 9)
10
11const RequiredHashChangedEvent = "CLARequiredHashChanged"
12
13// ProposeNewCLA creates a govdao proposal to update the CLA document hash and URL.
14// When executed, it resets all existing signatures.
15// Propose an empty hash to disable CLA enforcement.
16func ProposeNewCLA(cur realm, newHash, newURL string) dao.ProposalRequest {
17	cb := func(cur realm) error {
18		setRequiredHash(newHash)
19		claURL = newURL
20		return nil
21	}
22
23	desc := "Propose updating the CLA requirement.\n\n"
24	if requiredHash != "" {
25		desc += "Current hash: " + requiredHash + "\n"
26	}
27	if claURL != "" {
28		desc += "Current URL: " + claURL + "\n"
29	}
30	if newHash != "" {
31		desc += "New hash: " + newHash + "\n"
32	}
33	if newURL != "" {
34		desc += "New URL: " + newURL + "\n"
35	}
36	if newHash == "" {
37		desc += "This proposal disables CLA enforcement.\n"
38	}
39
40	return dao.NewProposalRequest(
41		"Update CLA requirement",
42		desc,
43		dao.NewSimpleExecutor(0, cur, cb, helplink.Realm("gno.land/r/sys/cla").Home()),
44	)
45}
46
47func setRequiredHash(newHash string) {
48	prevHash := requiredHash
49	requiredHash = newHash
50	signatures = addrset.Set{} // reset all signatures
51
52	chain.Emit(
53		RequiredHashChangedEvent,
54		"from", prevHash,
55		"to", newHash,
56	)
57}