proposal.gno

2.55 Kb ยท 94 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(cur realm, address_XXX std.Address) dao.ProposalRequest {
22	var (
23		valoper     = valopers.GetByAddr(address_XXX)
24		votingPower = uint64(1)
25	)
26
27	exist := validators.IsValidator(address_XXX)
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_XXX)
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(cur realm, newInstructions string) dao.ProposalRequest {
73	cb := valopers.NewInstructionsProposalCallback(newInstructions)
74	// Create a proposal
75	title := "/p/gnoland/valopers: Update instructions"
76	description := ufmt.Sprintf("Update the instructions to: \n\n%s", newInstructions)
77
78	e := dao.NewSimpleExecutor(cb, "")
79
80	return dao.NewProposalRequest(title, description, e)
81}
82
83// ProposeNewMinFee creates a proposal to the GovDAO
84// for updating the minimum fee to register a new valoper.
85func ProposeNewMinFeeProposalRequest(cur realm, newMinFee int64) dao.ProposalRequest {
86	cb := valopers.NewMinFeeProposalCallback(newMinFee)
87	// Create a proposal
88	title := "/p/gnoland/valopers: Update minFee"
89	description := ufmt.Sprintf("Update the minimum register fee to: %d ugnot", newMinFee)
90
91	e := dao.NewSimpleExecutor(cb, "")
92
93	return dao.NewProposalRequest(title, description, e)
94}