diff --git a/pkg/governance/api.go b/pkg/governance/api.go index 4b778f4..d3eb237 100644 --- a/pkg/governance/api.go +++ b/pkg/governance/api.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 { diff --git a/pkg/governance/cli.go b/pkg/governance/cli.go index 485dacb..a605758 100644 --- a/pkg/governance/cli.go +++ b/pkg/governance/cli.go @@ -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, }) }