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