proposal.gno
2.50 Kb ยท 96 lines
1package valopers_proposal
2
3import (
4 "errors"
5 "std"
6
7 "gno.land/p/demo/ufmt"
8 pVals "gno.land/p/sys/validators"
9 valopers "gno.land/r/gnoland/valopers"
10 "gno.land/r/gov/dao"
11 validators "gno.land/r/sys/validators/v2"
12)
13
14var (
15 ErrValidatorMissing = errors.New("the validator is missing")
16 ErrSameValues = errors.New("the valoper has the same voting power and pubkey")
17)
18
19// NewValidatorProposalRequest creates a proposal request to the GovDAO
20// for adding the given valoper to the validator set.
21func NewValidatorProposalRequest(address std.Address) dao.ProposalRequest {
22 var (
23 valoper = valopers.GetByAddr(address)
24 votingPower = uint64(1)
25 )
26
27 exist := validators.IsValidator(address)
28
29 // Determine the voting power
30 if !valoper.KeepRunning {
31 if !exist {
32 panic(ErrValidatorMissing)
33 }
34 votingPower = uint64(0)
35 }
36
37 if exist {
38 validator := validators.GetValidator(address)
39 if validator.VotingPower == votingPower && validator.PubKey == valoper.PubKey {
40 panic(ErrSameValues)
41 }
42 }
43
44 changesFn := func() []pVals.Validator {
45 return []pVals.Validator{
46 {
47 Address: valoper.Address,
48 PubKey: valoper.PubKey,
49 VotingPower: votingPower,
50 },
51 }
52 }
53
54 // Craft the proposal title
55 title := ufmt.Sprintf(
56 "Add valoper %s to the valset",
57 valoper.Moniker,
58 )
59
60 description := ufmt.Sprintf("Valoper profile: [%s](/r/gnoland/valopers:%s)\n\n%s",
61 valoper.Moniker,
62 valoper.Address,
63 valoper.Render(),
64 )
65
66 // Create the request
67 return validators.NewPropRequest(changesFn, title, description)
68}
69
70// ProposeNewInstructionsProposalRequest creates a proposal to the GovDAO
71// for updating the realm instructions.
72func ProposeNewInstructionsProposalRequest(newInstructions string) dao.ProposalRequest {
73 cb := valopers.NewInstructionsProposalCallback(newInstructions)
74
75 // Create a proposal
76 title := "/p/gnoland/valopers: Update instructions"
77 description := ufmt.Sprintf("Update the instructions to: \n\n%s", newInstructions)
78
79 e := dao.NewSimpleExecutor(cb, "")
80
81 return dao.NewProposalRequest(title, description, e)
82}
83
84// ProposeNewMinFee creates a proposal to the GovDAO
85// for updating the minimum fee to register a new valoper.
86func ProposeNewMinFeeProposalRequest(newMinFee int64) dao.ProposalRequest {
87 cb := valopers.NewMinFeeProposalCallback(newMinFee)
88
89 // Create a proposal
90 title := "/p/gnoland/valopers: Update minFee"
91 description := ufmt.Sprintf("Update the minimum register fee to: %d ugnot", newMinFee)
92
93 e := dao.NewSimpleExecutor(cb, "")
94
95 return dao.NewProposalRequest(title, description, e)
96}