Search Apps Documentation Source Content File Folder Download Copy Actions Download

proposal.gno

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