Skip to content

Commit

Permalink
Answer range (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantudor authored Mar 15, 2021
1 parent c2ee6e5 commit 18eaa5b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
34 changes: 19 additions & 15 deletions dao.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package navcoind

import "encoding/json"

type Proposal struct {
Version uint32 `json:"version"`
Hash string `json:"hash"`
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions navcoind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 18eaa5b

Please sign in to comment.