prop1_filetest.gno

2.99 Kb ยท 131 lines
  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	pVals "gno.land/p/sys/validators"
 14	govdao "gno.land/r/gov/dao"
 15	"gno.land/r/sys/validators"
 16)
 17
 18const daoPkgPath = "gno.land/r/gov/dao"
 19
 20func init() {
 21	membersFn := func() []std.Address {
 22		return []std.Address{
 23			std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"),
 24		}
 25	}
 26
 27	mExec := govdao.NewPropExecutor(membersFn)
 28
 29	comment := "adding someone to vote"
 30	id := govdao.Propose(comment, mExec)
 31	govdao.ExecuteProposal(id)
 32
 33	changesFn := func() []pVals.Validator {
 34		return []pVals.Validator{
 35			{
 36				Address:     std.Address("g12345678"),
 37				PubKey:      "pubkey",
 38				VotingPower: 10, // add a new validator
 39			},
 40			{
 41				Address:     std.Address("g000000000"),
 42				PubKey:      "pubkey",
 43				VotingPower: 10, // add a new validator
 44			},
 45			{
 46				Address:     std.Address("g000000000"),
 47				PubKey:      "pubkey",
 48				VotingPower: 0, // remove an existing validator
 49			},
 50		}
 51	}
 52
 53	// Wraps changesFn to emit a certified event only if executed from a
 54	// complete governance proposal process.
 55	executor := validators.NewPropExecutor(changesFn)
 56
 57	// Create a proposal.
 58	// XXX: payment
 59	comment = "manual valset changes proposal example"
 60	govdao.Propose(comment, executor)
 61}
 62
 63func main() {
 64	println("--")
 65	println(govdao.Render(""))
 66	println("--")
 67	println(govdao.Render("1"))
 68	println("--")
 69	govdao.VoteOnProposal(1, "YES")
 70	println("--")
 71	println(govdao.Render("1"))
 72	println("--")
 73	println(validators.Render(""))
 74	println("--")
 75	govdao.ExecuteProposal(1)
 76	println("--")
 77	println(govdao.Render("1"))
 78	println("--")
 79	println(validators.Render(""))
 80}
 81
 82// Output:
 83// --
 84// - [0](/r/gov/dao:0) - adding someone to vote (**succeeded**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
 85// - [1](/r/gov/dao:1) - manual valset changes proposal example (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
 86//
 87// --
 88// # Prop #1
 89//
 90// manual valset changes proposal example
 91//
 92// Status: active
 93//
 94// Voting status: YES: 0, NO: 0, percent: 0, members: 1
 95//
 96// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
 97//
 98//
 99// --
100// --
101// # Prop #1
102//
103// manual valset changes proposal example
104//
105// Status: accepted
106//
107// Voting status: YES: 1, NO: 0, percent: 100, members: 1
108//
109// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
110//
111//
112// --
113// No valset changes to apply.
114// --
115// --
116// # Prop #1
117//
118// manual valset changes proposal example
119//
120// Status: succeeded
121//
122// Voting status: YES: 1, NO: 0, percent: 100, members: 1
123//
124// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
125//
126//
127// --
128// Valset changes:
129// - #123: g12345678 (10)
130// - #123: g000000000 (10)
131// - #123: g000000000 (0)