1// Please note that this package is intended for demonstration purposes only.
2// You could execute this code (the init part) by running a `maketx run` command
3// or by uploading a similar package to a personal namespace.
4//
5// For the specific case of validators, a `r/gnoland/valopers` will be used to
6// organize the lifecycle of validators (register, etc), and this more complex
7// contract will be responsible to generate proposals.
8package main
9
10import (
11 "std"
12
13 "gno.land/p/demo/dao"
14 pVals "gno.land/p/sys/validators"
15 govdao "gno.land/r/gov/dao/v2"
16 validators "gno.land/r/sys/validators/v2"
17)
18
19func init() {
20 changesFn := func() []pVals.Validator {
21 return []pVals.Validator{
22 {
23 Address: std.Address("g12345678"),
24 PubKey: "pubkey",
25 VotingPower: 10, // add a new validator
26 },
27 {
28 Address: std.Address("g000000000"),
29 PubKey: "pubkey",
30 VotingPower: 10, // add a new validator
31 },
32 {
33 Address: std.Address("g000000000"),
34 PubKey: "pubkey",
35 VotingPower: 0, // remove an existing validator
36 },
37 }
38 }
39
40 // Wraps changesFn to emit a certified event only if executed from a
41 // complete governance proposal process.
42 executor := validators.NewPropExecutor(changesFn)
43
44 // Create a proposal
45 description := "manual valset changes proposal example"
46
47 prop := dao.ProposalRequest{
48 Description: description,
49 Executor: executor,
50 }
51
52 govdao.Propose(prop)
53}
54
55func main() {
56 println("--")
57 println(govdao.Render(""))
58 println("--")
59 println(govdao.Render("0"))
60 println("--")
61 govdao.VoteOnProposal(0, dao.YesVote)
62 println("--")
63 println(govdao.Render("0"))
64 println("--")
65 println(validators.Render(""))
66 println("--")
67 govdao.ExecuteProposal(0)
68 println("--")
69 println(govdao.Render("0"))
70 println("--")
71 println(validators.Render(""))
72}
73
74// Output:
75// --
76// - [Proposal #0](/r/gov/dao/v2:0) - (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
77//
78// --
79// # Prop #0
80//
81// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
82//
83// manual valset changes proposal example
84//
85// Status: active
86//
87// Voting stats: YAY 0 (0%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 10 (100%)
88//
89// Threshold met: false
90//
91//
92// --
93// --
94// # Prop #0
95//
96// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
97//
98// manual valset changes proposal example
99//
100// Status: accepted
101//
102// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
103//
104// Threshold met: true
105//
106//
107// --
108// No valset changes to apply.
109// --
110// --
111// # Prop #0
112//
113// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
114//
115// manual valset changes proposal example
116//
117// Status: execution successful
118//
119// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
120//
121// Threshold met: true
122//
123//
124// --
125// Valset changes:
126// - #123: g12345678 (10)
127// - #123: g000000000 (10)
128// - #123: g000000000 (0)
prop1_filetest.gno
2.80 Kb ยท 128 lines