Search Apps Documentation Source Content File Folder Download Copy Actions Download

cla.gno

0.94 Kb · 43 lines
 1package cla
 2
 3import (
 4	"chain"
 5	"chain/runtime"
 6
 7	"gno.land/p/moul/addrset"
 8)
 9
10const SignedEvent = "CLASigned"
11
12var (
13	requiredHash string // SHA256 hash of the CLA document; empty = enforcement disabled
14	claURL       string // URL where the CLA document can be found
15	signatures   addrset.Set
16)
17
18// Sign records a CLA signature for the caller.
19// The hash must match the current required hash.
20func Sign(cur realm, hash string) {
21	if hash != requiredHash {
22		panic("hash does not match required CLA hash")
23	}
24
25	caller := runtime.PreviousRealm().Address()
26	signatures.Add(caller)
27
28	chain.Emit(
29		SignedEvent,
30		"signer", caller.String(),
31		"hash", hash,
32	)
33}
34
35// HasValidSignature checks if an address has signed the current required CLA.
36// Returns true if CLA enforcement is disabled (requiredHash == ""),
37// or if the address has signed.
38func HasValidSignature(addr address) bool {
39	if requiredHash == "" {
40		return true
41	}
42	return signatures.Has(addr)
43}