poc.gno
1.38 Kb ยท 59 lines
1package validators
2
3import (
4 "std"
5
6 "gno.land/p/sys/validators"
7 "gno.land/r/gov/dao"
8)
9
10const errNoChangesProposed = "no set changes proposed"
11
12// NewPropRequest creates a new proposal request that wraps a changes closure
13// proposal. This wrapper is required to ensure the GovDAO Realm actually
14// executed the callback.
15func NewPropRequest(changesFn func() []validators.Validator, title, description string) dao.ProposalRequest {
16 if changesFn == nil {
17 panic(errNoChangesProposed)
18 }
19
20 callback := func() error {
21 for _, change := range changesFn() {
22 if change.VotingPower == 0 {
23 // This change request is to remove the validator
24 removeValidator(change.Address)
25
26 continue
27 }
28
29 // This change request is to add the validator
30 addValidator(change)
31 }
32
33 return nil
34 }
35
36 e := dao.NewSimpleExecutor(callback, "")
37
38 return dao.NewProposalRequest(title, description, e)
39}
40
41// IsValidator returns a flag indicating if the given bech32 address
42// is part of the validator set
43func IsValidator(addr std.Address) bool {
44 return vp.IsValidator(addr)
45}
46
47// GetValidator returns the typed validator
48func GetValidator(addr std.Address) validators.Validator {
49 if validator, err := vp.GetValidator(addr); err == nil {
50 return validator
51 }
52
53 panic("validator not found")
54}
55
56// GetValidators returns the typed validator set
57func GetValidators() []validators.Validator {
58 return vp.GetValidators()
59}