Skip to content

Commit

Permalink
chore: fixup
Browse files Browse the repository at this point in the history
Signed-off-by: moul <[email protected]>
  • Loading branch information
moul committed Oct 31, 2024
1 parent b00abbe commit 12f0140
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 111 deletions.
95 changes: 0 additions & 95 deletions examples/gno.land/r/gov/dao/prop3_filetest.gno

This file was deleted.

112 changes: 112 additions & 0 deletions examples/gno.land/r/gov/dao/v2/prop4_filetest.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package main

import (
"gno.land/p/demo/dao"
"gno.land/r/gov/dao/bridge"
govdaov2 "gno.land/r/gov/dao/v2"
"gno.land/r/sys/params"
)

func init() {
/*{ // prop0
membersFn := func() []std.Address {
return []std.Address{
std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"),
}
}
mExec := bridge.GovDAO().NewMemberPropExecutor(membersFn)
comment := "adding someone to vote"
id := bridge.GovDAO().Propose(comment, mExec)
bridge.GovDAO().ExecuteProposal(id)
}*/

{ // prop0
mExec := params.NewStringPropExecutor("prop1.string", "value1")
comment := "setting prop1.string param"
prop := dao.ProposalRequest{
Description: comment,
Executor: mExec,
}
id := bridge.GovDAO().Propose(prop)
println("new prop", id)
}

{ // prop1
mExec := params.NewInt64PropExecutor("prop2.int64", 12345)
comment := "setting prop2.int64 param"
prop := dao.ProposalRequest{
Description: comment,
Executor: mExec,
}
id := bridge.GovDAO().Propose(prop)
println("new prop", id)
}
}

func main() {
println("--")
println(govdaov2.Render(""))
println("--")
println(govdaov2.Render("1"))
println("--")
bridge.GovDAO().VoteOnProposal(1, "YES")
println("--")
println(govdaov2.Render("1"))
println("--")
bridge.GovDAO().ExecuteProposal(1)
println("--")
println(govdaov2.Render("1"))
}

// Events:
// [{"type":"ProposalAdded","attrs":[{"key":"proposal-id","value":"0"},{"key":"proposal-author","value":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"}],"pkg_path":"gno.land/r/gov/dao/v2","func":"EmitProposalAdded"},{"type":"ProposalAdded","attrs":[{"key":"proposal-id","value":"1"},{"key":"proposal-author","value":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"}],"pkg_path":"gno.land/r/gov/dao/v2","func":"EmitProposalAdded"},{"type":"VoteAdded","attrs":[{"key":"proposal-id","value":"1"},{"key":"author","value":"g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm"},{"key":"option","value":"YES"}],"pkg_path":"gno.land/r/gov/dao/v2","func":"EmitVoteAdded"},{"type":"ProposalAccepted","attrs":[{"key":"proposal-id","value":"1"}],"pkg_path":"gno.land/r/gov/dao/v2","func":"EmitProposalAccepted"},{"type":"set","attrs":[{"key":"k","value":"prop2.int64"}],"pkg_path":"gno.land/r/sys/params","func":""},{"type":"ProposalExecuted","attrs":[{"key":"proposal-id","value":"1"},{"key":"exec-status","value":"accepted"}],"pkg_path":"gno.land/r/gov/dao/v2","func":"ExecuteProposal"}]

// Output:
// new prop 0
// new prop 1
// --
// - [Proposal #0](/r/gov/dao/v2:0) - (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
// - [Proposal #1](/r/gov/dao/v2:1) - (**active**)(by g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm)
//
// --
// # Prop #1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
// setting prop2.int64 param
//
// Status: active
//
// Voting stats: YAY 0 (0%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 10 (100%)
//
// Threshold met: false
//
//
// --
// --
// # Prop #1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
// setting prop2.int64 param
//
// Status: accepted
//
// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
//
// Threshold met: true
//
//
// --
// --
// # Prop #1
//
// Author: g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm
//
// setting prop2.int64 param
//
// Status: execution successful
//
// Voting stats: YAY 10 (100%), NAY 0 (0%), ABSTAIN 0 (0%), HAVEN'T VOTED 0 (0%)
//
// Threshold met: true
26 changes: 10 additions & 16 deletions examples/gno.land/r/sys/params/params.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,35 @@ package params
import (
"std"

"gno.land/p/gov/proposal"
"gno.land/p/demo/dao"
"gno.land/r/gov/dao/bridge"
)

const daoPkgPath = "gno.land/r/gov/dao"

func NewStringPropExecutor(key string, value string) proposal.Executor {
func NewStringPropExecutor(key string, value string) dao.Executor {
return newPropExecutor(key, func() { std.SetParamString(key, value) })
}

func NewInt64PropExecutor(key string, value int64) proposal.Executor {
func NewInt64PropExecutor(key string, value int64) dao.Executor {
return newPropExecutor(key, func() { std.SetParamInt64(key, value) })
}

func NewUint64PropExecutor(key string, value uint64) proposal.Executor {
func NewUint64PropExecutor(key string, value uint64) dao.Executor {
return newPropExecutor(key, func() { std.SetParamUint64(key, value) })
}

func NewBoolPropExecutor(key string, value bool) proposal.Executor {
func NewBoolPropExecutor(key string, value bool) dao.Executor {
return newPropExecutor(key, func() { std.SetParamBool(key, value) })
}

func NewBytesPropExecutor(key string, value []byte) proposal.Executor {
func NewBytesPropExecutor(key string, value []byte) dao.Executor {
return newPropExecutor(key, func() { std.SetParamBytes(key, value) })
}

func newPropExecutor(key string, fn func()) proposal.Executor {
func newPropExecutor(key string, fn func()) dao.Executor {
callback := func() error {
if std.PrevRealm().PkgPath() != daoPkgPath {
panic("should be executed from govdao")
}
std.Emit("set",
"k", key,
)
fn()
std.Emit("set", "k", key)
return nil
}
return proposal.NewExecutor(callback)
return bridge.GovDAO().NewGovDAOExecutor(callback)
}

0 comments on commit 12f0140

Please sign in to comment.