Skip to content

Commit

Permalink
Merge pull request #290 from MaxMustermann2/snapshot-org-test
Browse files Browse the repository at this point in the history
governance: add voting support for snapshot.org
  • Loading branch information
harmony-devops authored Aug 29, 2022
2 parents 1c24234 + 16347d8 commit dbd9901
Show file tree
Hide file tree
Showing 16 changed files with 562 additions and 1,445 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ all:
static:
make -C $(shell go env GOPATH)/src/github.com/harmony-one/mcl
make -C $(shell go env GOPATH)/src/github.com/harmony-one/bls minimised_static BLS_SWAP_G=1
source $(shell go env GOPATH)/src/github.com/harmony-one/harmony/scripts/setup_bls_build_flags.sh && $(env) go build -o $(cli) -ldflags="$(ldflags) -w -extldflags \"-static\"" cmd/main.go
source $(shell go env GOPATH)/src/github.com/harmony-one/harmony/scripts/setup_bls_build_flags.sh && $(env) go build -o $(cli) -ldflags="$(ldflags) -w -extldflags \"-static -z muldefs\"" cmd/main.go
cp $(cli) hmy

debug:
Expand Down
35 changes: 7 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,15 @@ Check README for details on json file format.
20. Check which shard your BLS public key would be assigned to as a validator
./hmy --node=https://api.s0.t.hmny.io utility shard-for-bls <BLS_PUBLIC_KEY>
21. List Space In Governance
./hmy governance list-space
22. List Proposal In Space Of Governance
./hmy governance list-proposal --space=[space key, example: staking-testnet]
23. View Proposal In Governance
./hmy governance view-proposal --proposal=[proposal hash]
24. New Proposal In Space Of Governance
./hmy governance new-proposal --proposal-yaml=[file path] --key=[key name]
PS: key must first use (hmy keys import-private-key) to import
Yaml example(time is in UTC timezone):
space: staking-testnet
start: 2020-04-16 21:45:12
end: 2020-04-21 21:45:12
choices:
- yes
- no
title: this is title
body: |
this is body,
you can write mutli line
25. Vote Proposal In Space Of Governance
./hmy governance vote-proposal --proposal=[proposal hash] --choice=[your choice text, eg: yes] --key=[key name]
21. Vote on a governance proposal on https://snapshot.org
./hmy governance vote-proposal --space=[harmony-mainnet.eth] \
--proposal=<PROPOSAL_IPFS_HASH> --proposal-type=[single-choice] \
--choice=<VOTING_CHOICE(S)> --app=[APP] --key=<ACCOUNT_ADDRESS_OR_NAME> \
--privacy=[PRIVACY TYPE]
PS: key must first use (hmy keys import-private-key) to import
26. Enter Console
./hmy command --net=testnet --shard=0
22. Enter Console
./hmy command --net=testnet
```

# Sending batched transactions
Expand Down
115 changes: 26 additions & 89 deletions cmd/subcommands/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/harmony-one/go-sdk/pkg/governance"
"github.com/harmony-one/go-sdk/pkg/store"
"github.com/harmony-one/harmony/accounts"
Expand All @@ -11,9 +12,9 @@ import (
func init() {
cmdGovernance := &cobra.Command{
Use: "governance",
Short: "Support interaction with the Harmony governance app.",
Short: "Interact with the Harmony spaces on https://snapshot.org",
Long: `
Support interaction with the Harmony governance app, especially for validators that do not want to import their account private key into either metamask or onewallet.
Support interaction with the Harmony governance space on Snapshot, especially for validators that do not want to import their account private key into either metamask or onewallet.
`,
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Help()
Expand All @@ -22,97 +23,20 @@ Support interaction with the Harmony governance app, especially for validators t
}

cmdGovernance.AddCommand([]*cobra.Command{
{
Use: "list-space",
Short: "List all spaces of the governance app",
RunE: func(cmd *cobra.Command, args []string) error {
return governance.PrintListSpace()
},
},
commandListProposal(),
commandViewProposal(),
commandNewProposal(),
commandVote(),
}...)

RootCmd.AddCommand(cmdGovernance)
}

func commandListProposal() (cmd *cobra.Command) {
var space string

cmd = &cobra.Command{
Use: "list-proposal",
Short: "List all proposals for the given space",
RunE: func(cmd *cobra.Command, args []string) error {
return governance.PrintListProposals(space)
},
}

cmd.Flags().StringVar(&space, "space", "", "Space the proposal belongs to e.g. 'staking-mainnet'")
cmd.MarkFlagRequired("space")

return
}

func commandViewProposal() (cmd *cobra.Command) {
var proposal string

cmd = &cobra.Command{
Use: "view-proposal",
Short: "View a proposal",
RunE: func(cmd *cobra.Command, args []string) error {
return governance.PrintViewProposal(proposal)
},
}

cmd.Flags().StringVar(&proposal, "proposal", "", "Proposal hash")
cmd.MarkFlagRequired("proposal")

return
}

func commandNewProposal() (cmd *cobra.Command) {
var proposal string
var key string

cmd = &cobra.Command{
Use: "new-proposal",
Short: "Start a new proposal",
RunE: func(cmd *cobra.Command, args []string) error {
keyStore := store.FromAccountName(key)
passphrase, err := getPassphrase()
if err != nil {
return err
}

if len(keyStore.Accounts()) <= 0 {
return fmt.Errorf("Couldn't find address from the key")
}

account := accounts.Account{Address: keyStore.Accounts()[0].Address}
err = keyStore.Unlock(accounts.Account{Address: keyStore.Accounts()[0].Address}, passphrase)
if err != nil {
return err
}

return governance.NewProposal(keyStore, account, proposal)
},
}

cmd.Flags().StringVar(&proposal, "proposal-yaml", "", "Proposal yaml path")
cmd.Flags().StringVar(&key, "key", "", "Account address. Must first use (hmy keys import-private-key) to import.")
cmd.Flags().BoolVar(&userProvidesPassphrase, "passphrase", false, ppPrompt)
cmd.MarkFlagRequired("proposal-yaml")
cmd.MarkFlagRequired("key")

return
}

func commandVote() (cmd *cobra.Command) {
var space string
var proposal string
var choice string
var key string
var proposalType string
var privacy string
var app string

cmd = &cobra.Command{
Use: "vote-proposal",
Expand All @@ -125,7 +49,7 @@ func commandVote() (cmd *cobra.Command) {
}

if len(keyStore.Accounts()) <= 0 {
return fmt.Errorf("Couldn't find address from the key")
return fmt.Errorf("couldn't find address from the key")
}

account := accounts.Account{Address: keyStore.Accounts()[0].Address}
Expand All @@ -134,16 +58,29 @@ func commandVote() (cmd *cobra.Command) {
return err
}

return governance.Vote(keyStore, account, proposal, choice)
return governance.DoVote(keyStore, account, governance.Vote{
Space: space,
Proposal: proposal,
ProposalType: proposalType,
Choice: choice,
Privacy: privacy,
App: app,
From: account.Address.Hex(),
})
},
}

cmd.Flags().StringVar(&key, "key", "", "Account name. Must first use (hmy keys import-private-key) to import.")
cmd.Flags().StringVar(&space, "space", "harmony-mainnet.eth", "Snapshot space")
cmd.Flags().StringVar(&proposal, "proposal", "", "Proposal hash")
cmd.Flags().StringVar(&choice, "choice", "", "Vote choice e.g. 'agree' or 'disagree'")
cmd.Flags().StringVar(&key, "key", "", "Account address. Must first use (hmy keys import-private-key) to import.")
cmd.Flags().StringVar(&proposalType, "proposal-type", "single-choice", "Proposal type like single-choice, approval, quadratic, etc.")
cmd.Flags().StringVar(&choice, "choice", "", "Vote choice either as integer, list of integers (e.x. when using ranked choice voting), or string")
cmd.Flags().StringVar(&privacy, "privacy", "", "Vote privacy ex. shutter")
cmd.Flags().StringVar(&app, "app", "", "Voting app")
cmd.Flags().BoolVar(&userProvidesPassphrase, "passphrase", false, ppPrompt)
cmd.MarkFlagRequired("proposal")
cmd.MarkFlagRequired("choose")

cmd.MarkFlagRequired("key")
cmd.MarkFlagRequired("proposal")
cmd.MarkFlagRequired("choice")
return
}
37 changes: 8 additions & 29 deletions cmd/subcommands/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,14 @@ Check README for details on json file format.
./hmy --node=[NODE] utility shard-for-bls <BLS_PUBLIC_KEY>
%s
./hmy governance list-space
%s
./hmy governance list-proposal --space=[space key, example: staking-testnet]
%s
./hmy governance view-proposal --proposal=[proposal hash]
./hmy governance vote-proposal --space=[harmony-mainnet.eth] \
--proposal=<PROPOSAL_IPFS_HASH> --proposal-type=[single-choice] \
--choice=<VOTING_CHOICE(S)> --app=[APP] --key=<ACCOUNT_ADDRESS_OR_NAME> \
--privacy=[PRIVACY TYPE]
PS: key must first use (hmy keys import-private-key) to import
%s
./hmy governance new-proposal --proposal-yaml=[file path] --key=[account address]
PS: key must first use (hmy keys import-private-key) to import
Yaml example(time is in UTC timezone):
space: staking-testnet
start: 2020-04-16 21:45:12
end: 2020-04-21 21:45:12
choices:
- yes
- no
title: this is title
body: |
this is body,
you can write mutli line
%s
./hmy governance vote-proposal --proposal=[proposal hash] --choice=[your choise text, eg: yes] --key=[account address]
PS: key must first use (hmy keys import-private-key) to import
./hmy command --net=testnet
`,
g("1. Check account balance on given chain"),
g("2. Check sent transaction"),
Expand All @@ -152,10 +134,7 @@ PS: key must first use (hmy keys import-private-key) to import
g("18. Get current staking utility metrics"),
g("19. Check in-memory record of failed staking transactions"),
g("20. Check which shard your BLS public key would be assigned to as a validator"),
g("21. List Space In Governance"),
g("22. List Proposal In Space Of Governance"),
g("23. View Proposal In Governance"),
g("24. New Proposal In Space Of Governance"),
g("25. Vote Proposal In Space Of Governance"),
g("21. Vote on a governance proposal on https://snapshot.org"),
g("22. Enter console"),
)
)
21 changes: 4 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,28 @@ go 1.14

require (
github.com/aristanetworks/goarista v0.0.0-20191023202215-f096da5361bb // indirect
github.com/btcsuite/btcd v0.21.0-beta
github.com/btcsuite/btcutil v1.0.2
github.com/btcsuite/btcd v0.22.1
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cosmos/cosmos-sdk v0.37.0
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f // indirect
github.com/deckarep/golang-set v1.7.1
github.com/dop251/goja v0.0.0-20210427212725-462d53687b0d
github.com/ethereum/go-ethereum v1.9.23
github.com/fatih/color v1.9.0
github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26 // indirect
github.com/gorilla/handlers v1.4.0 // indirect
github.com/harmony-one/bls v0.0.7-0.20191214005344-88c23f91a8a9
github.com/harmony-one/harmony v1.10.2-0.20210123081216-6993b9ad0ca1
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365 // indirect
github.com/ipfs/go-todocounter v0.0.2 // indirect
github.com/jackpal/gateway v1.0.6 // indirect
github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect
github.com/karalabe/hid v1.0.0
github.com/libp2p/go-libp2p-host v0.1.0 // indirect
github.com/libp2p/go-libp2p-net v0.1.0 // indirect
github.com/libp2p/go-libp2p-routing v0.1.0 // indirect
github.com/libp2p/go-sockaddr v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.9
github.com/mitchellh/go-homedir v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v0.0.5
github.com/tyler-smith/go-bip39 v1.0.2
github.com/uber/jaeger-client-go v2.20.1+incompatible // indirect
github.com/uber/jaeger-lib v2.2.0+incompatible // indirect
github.com/valyala/fasthttp v1.2.0
github.com/valyala/fastjson v1.6.3
github.com/wangjia184/sortedset v0.0.0-20160527075905-f5d03557ba30 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/ethereum/go-ethereum => github.com/ethereum/go-ethereum v1.9.9
Expand Down
Loading

0 comments on commit dbd9901

Please sign in to comment.