Search Apps Documentation Source Content File Folder Download Copy Actions Download

proposal.gno

3.07 Kb · 94 lines
 1package proposal
 2
 3import (
 4	"errors"
 5
 6	"gno.land/p/nt/ufmt/v0"
 7	valopers "gno.land/r/gnops/valopers"
 8	"gno.land/r/gov/dao"
 9	sysparams "gno.land/r/sys/params"
10	validators "gno.land/r/sys/validators/v3"
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 (or removing) the given valoper to/from the validator set.
20//
21// Signature is preserved for historical-replay compatibility (gnoland-1
22// callers call this with a single address). Body is rewired to call
23// v3's operator-keyed NewValidatorProposalRequest with a single-element
24// slice; v3's executor re-resolves the signing pubkey from valoperCache
25// at execution time, so a mid-flight rotation publishes the current key.
26func NewValidatorProposalRequest(cur realm, addr address) dao.ProposalRequest {
27	var (
28		valoper     = valopers.GetByAddr(addr)
29		votingPower = uint64(1)
30	)
31
32	exist := validators.IsValidator(valoper.SigningAddress)
33
34	// Determine the voting power
35	if !valoper.KeepRunning {
36		if !exist {
37			panic(ErrValidatorMissing)
38		}
39		votingPower = uint64(0)
40	}
41
42	if exist {
43		validator := validators.GetValidator(valoper.SigningAddress)
44		if validator.VotingPower == votingPower && validator.PubKey == valoper.SigningPubKey {
45			panic(ErrSameValues)
46		}
47	}
48
49	// Craft the proposal title and description, framed around the
50	// valoper profile. Voters see the operator identity (moniker +
51	// operator address); the signing key is an implementation detail
52	// resolved at execution time by v3's executor.
53	title := ufmt.Sprintf(
54		"Add valoper %s to the valset",
55		valoper.Moniker,
56	)
57
58	description := ufmt.Sprintf("Valoper profile: [%s](/r/gnops/valopers:%s)\n\n%s",
59		valoper.Moniker,
60		valoper.OperatorAddress,
61		valoper.Render(),
62	)
63
64	return validators.NewValidatorProposalRequest(
65		[]validators.ValoperChange{
66			{OperatorAddress: valoper.OperatorAddress, Power: votingPower},
67		},
68		title,
69		description,
70	)
71}
72
73// ProposeNewInstructionsProposalRequest creates a proposal to the GovDAO
74// for updating the realm instructions.
75func ProposeNewInstructionsProposalRequest(cur realm, newInstructions string) dao.ProposalRequest {
76	cb := valopers.NewInstructionsProposalCallback(newInstructions)
77	// Create a proposal
78	title := "/p/gnops/valopers: Update instructions"
79	description := ufmt.Sprintf("Update the instructions to: \n\n%s", newInstructions)
80
81	e := dao.NewSimpleExecutor(cb, "")
82
83	return dao.NewProposalRequest(title, description, e)
84}
85
86// ProposeNewMinFeeProposalRequest creates a proposal to the GovDAO
87// for updating the minimum fee to register a new valoper. Signature
88// preserved for historical-replay compatibility (gnoland-1's
89// set_minfee.gno MsgRun calls this); body now delegates to the
90// generic sys/params factory so the fee lives in
91// node:valoper:register_fee.
92func ProposeNewMinFeeProposalRequest(cur realm, newMinFee int64) dao.ProposalRequest {
93	return sysparams.NewSysParamUint64PropRequest("node", "valoper", "register_fee", uint64(newMinFee))
94}