6 chainjson "github.com/vapor/encoding/json"
10 Vote string `json:"vote"`
11 VoteNum uint64 `json:"vote_number"`
14 type voteInfoSlice []*voteInfo
16 func (v voteInfoSlice) Len() int { return len(v) }
17 func (v voteInfoSlice) Less(i, j int) bool { return v[i].VoteNum > v[j].VoteNum }
18 func (v voteInfoSlice) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
20 func (a *API) getVoteResult(req struct {
21 BlockHash chainjson.HexBytes `json:"block_hash"`
22 BlockHeight uint64 `json:"block_height"`
24 blockHash := hexBytesToHash(req.BlockHash)
25 if len(req.BlockHash) != 32 {
26 blockHeader, err := a.chain.GetHeaderByHeight(req.BlockHeight)
28 return NewErrorResponse(err)
31 blockHash = blockHeader.Hash()
34 consensusResult, err := a.chain.GetConsensusResultByHash(&blockHash)
36 return NewErrorResponse(err)
39 voteInfos := []*voteInfo{}
40 for pubKey, voteNum := range consensusResult.NumOfVote {
41 voteInfos = append(voteInfos, &voteInfo{
46 sort.Sort(voteInfoSlice(voteInfos))
47 return NewSuccessResponse(voteInfos)