support multi-choice governance

pull/262/head
Lutty 4 years ago committed by Leo Chen
parent c0d03b74b7
commit ab1cb6df13
  1. 34
      pkg/governance/api.go
  2. 7
      pkg/governance/cli.go

@ -3,6 +3,8 @@ package governance
import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
type Space struct {
@ -71,8 +73,36 @@ type ProposalIPFSMsg struct {
}
type ProposalVoteMsgPayload struct {
Choice int `json:"choice,string"`
Proposal string `json:"proposal"`
Choice json.RawMessage `json:"choice"`
Proposal string `json:"proposal"`
}
func (p *ProposalVoteMsgPayload) choices() []int {
var one int
err := json.Unmarshal(p.Choice, &one)
if err == nil {
return []int{one}
}
var many string
err = json.Unmarshal(p.Choice, &many)
if err != nil {
return []int{}
}
splits := strings.Split(many, "-")
ret := make([]int, 0, len(splits))
for _, split := range splits {
number, err := strconv.Atoi(split)
if err != nil {
return []int{}
}
ret = append(ret, number)
}
return ret
}
type ProposalVoteMsg struct {

@ -99,9 +99,14 @@ func PrintViewProposal(proposalHash string) error {
}
}
choices := make([]string, 0)
for _, choice := range vote.Msg.Payload.choices() {
choices = append(choices, proposals.parsedMsg.Payload.Choices[choice-1])
}
table.Append([]string{
addr,
proposals.parsedMsg.Payload.Choices[vote.Msg.Payload.Choice-1],
strings.Join(choices, ", "),
stack,
})
}

Loading…
Cancel
Save