github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/api/consensus.go (about) 1 package api 2 3 type VoteInfo struct { 4 Vote string `json:"vote"` 5 VoteNum uint64 `json:"vote_number"` 6 } 7 8 func (a *API) getVoteResult(req BlockReq) Response { 9 blockHash := hexBytesToHash(req.BlockHash) 10 if len(req.BlockHash) != 32 { 11 blockHeader, err := a.chain.GetHeaderByHeight(req.BlockHeight) 12 if err != nil { 13 return NewErrorResponse(err) 14 } 15 16 blockHash = blockHeader.Hash() 17 } 18 19 validators, err := a.chain.AllValidators(&blockHash) 20 if err != nil { 21 return NewErrorResponse(err) 22 } 23 24 voteInfos := []*VoteInfo{} 25 for _, validator := range validators { 26 voteInfos = append(voteInfos, &VoteInfo{ 27 Vote: validator.PubKey, 28 VoteNum: validator.VoteNum, 29 }) 30 } 31 return NewSuccessResponse(voteInfos) 32 }