OSDN Git Service

add get vote result (#345)
[bytom/vapor.git] / api / bbft.go
index 83cad1e..0ab6fe6 100644 (file)
@@ -6,15 +6,16 @@ import (
        chainjson "github.com/vapor/encoding/json"
 )
 
-type voteInfo struct {
+type VoteInfo struct {
        Vote    string `json:"vote"`
        VoteNum uint64 `json:"vote_number"`
 }
 
-type voteInfoSlice []*voteInfo
-func (v voteInfoSlice) Len() int { return len(v) }
+type voteInfoSlice []*VoteInfo
+
+func (v voteInfoSlice) Len() int           { return len(v) }
 func (v voteInfoSlice) Less(i, j int) bool { return v[i].VoteNum > v[j].VoteNum }
-func (v voteInfoSlice) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
+func (v voteInfoSlice) Swap(i, j int)      { v[i], v[j] = v[j], v[i] }
 
 func (a *API) getVoteResult(req struct {
        BlockHash   chainjson.HexBytes `json:"block_hash"`
@@ -30,14 +31,14 @@ func (a *API) getVoteResult(req struct {
                blockHash = blockHeader.Hash()
        }
 
-       voteResult, err := a.chain.GetVoteResultByHash(&blockHash)
+       consensusResult, err := a.chain.GetConsensusResultByHash(&blockHash)
        if err != nil {
                return NewErrorResponse(err)
        }
 
-       voteInfos := []*voteInfo{}
-       for pubKey, voteNum := range voteResult.NumOfVote {
-               voteInfos = append(voteInfos, &voteInfo{
+       voteInfos := []*VoteInfo{}
+       for pubKey, voteNum := range consensusResult.NumOfVote {
+               voteInfos = append(voteInfos, &VoteInfo{
                        Vote:    pubKey,
                        VoteNum: voteNum,
                })