poc.gno

1.18 Kb ยท 52 lines
 1package validators
 2
 3import (
 4	"std"
 5
 6	"gno.land/p/demo/dao"
 7	"gno.land/p/sys/validators"
 8	"gno.land/r/gov/dao/bridge"
 9)
10
11const errNoChangesProposed = "no set changes proposed"
12
13// NewPropExecutor creates a new executor that wraps a changes closure
14// proposal. This wrapper is required to ensure the GovDAO Realm actually
15// executed the callback.
16//
17// Concept adapted from:
18// https://github.com/gnolang/gno/pull/1945
19func NewPropExecutor(changesFn func() []validators.Validator) dao.Executor {
20	if changesFn == nil {
21		panic(errNoChangesProposed)
22	}
23
24	callback := func() error {
25		for _, change := range changesFn() {
26			if change.VotingPower == 0 {
27				// This change request is to remove the validator
28				removeValidator(change.Address)
29
30				continue
31			}
32
33			// This change request is to add the validator
34			addValidator(change)
35		}
36
37		return nil
38	}
39
40	return bridge.GovDAO().NewGovDAOExecutor(callback)
41}
42
43// IsValidator returns a flag indicating if the given bech32 address
44// is part of the validator set
45func IsValidator(addr std.Address) bool {
46	return vp.IsValidator(addr)
47}
48
49// GetValidators returns the typed validator set
50func GetValidators() []validators.Validator {
51	return vp.GetValidators()
52}