diff --git a/dao.go b/dao.go index de8cda7..0449c34 100644 --- a/dao.go +++ b/dao.go @@ -1,5 +1,7 @@ package navcoind +import "encoding/json" + type Proposal struct { Version uint32 `json:"version"` Hash string `json:"hash"` @@ -63,21 +65,23 @@ type ConsensusParameter struct { } type Consultation struct { - Version uint32 `json:"version"` - Hash string `json:"hash"` - BlockHash string `json:"blockhash"` - Question string `json:"question"` - Support int `json:"support"` - Abstain int `json:"abstain"` - Answers []*Answer `json:"answers"` - Min int `json:"min"` - Max int `json:"max"` - VotingCyclesFromCreation int `json:"votingCyclesFromCreation"` - VotingCycleForState Cycle `json:"votingCycleForState"` - Status string `json:"status"` - State int `json:"state"` - StateChangedOnBlock string `json:"stateChangedOnBlock"` - MapState map[int]string `json:"mapState"` + Version uint32 `json:"version"` + Hash string `json:"hash"` + BlockHash string `json:"blockhash"` + Question string `json:"question"` + Support int `json:"support"` + Abstain int `json:"abstain"` + RawAnswers json.RawMessage `json:"answers"` + Answers []*Answer `json:"-"` + RangeAnswers map[string]int `json:"-"` + Min int `json:"min"` + Max int `json:"max"` + VotingCyclesFromCreation int `json:"votingCyclesFromCreation"` + VotingCycleForState Cycle `json:"votingCycleForState"` + Status string `json:"status"` + State int `json:"state"` + StateChangedOnBlock string `json:"stateChangedOnBlock"` + MapState map[int]string `json:"mapState"` } type Cycle struct { diff --git a/navcoind.go b/navcoind.go index ef8988c..be935f9 100644 --- a/navcoind.go +++ b/navcoind.go @@ -849,5 +849,19 @@ func (b *Navcoind) GetConsultation(hash string) (consultation Consultation, err return } err = json.Unmarshal(r.Result, &consultation) + + if consultation.Version>>1&1 == 1 { + var answers []map[string]int + if err := json.Unmarshal(consultation.RawAnswers, &answers); err != nil { + return + } + consultation.RangeAnswers = answers[0] + } else { + var answers []*Answer + if err := json.Unmarshal(consultation.RawAnswers, &answers); err != nil { + return + } + consultation.Answers = answers + } return }