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