chainjson "github.com/vapor/encoding/json"
)
-type voteInfo struct {
+type VoteInfo struct {
Vote string `json:"vote"`
VoteNum uint64 `json:"vote_number"`
}
-type voteInfoSlice []*voteInfo
+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 }
return NewErrorResponse(err)
}
- voteInfos := []*voteInfo{}
+ voteInfos := []*VoteInfo{}
for pubKey, voteNum := range consensusResult.NumOfVote {
- voteInfos = append(voteInfos, &voteInfo{
+ voteInfos = append(voteInfos, &VoteInfo{
Vote: pubKey,
VoteNum: voteNum,
})
if err != nil {
return nil, errors.Wrap(err, "json marshal")
}
-
resp := &api.GetRawBlockResp{}
return resp.RawBlock, n.request(url, payload, resp)
}
+
+func (n *Node) GetVoteByHash(hash string) ([]api.VoteInfo, error) {
+ return n.getVoteResult(&getVoteResultReq{BlockHash: hash})
+}
+
+func (n *Node) GetVoteByHeight(height uint64) ([]api.VoteInfo, error) {
+ return n.getVoteResult(&getVoteResultReq{BlockHeight: height})
+}
+
+type getVoteResultReq struct {
+ BlockHeight uint64 `json:"block_height"`
+ BlockHash string `json:"block_hash"`
+}
+
+func (n *Node) getVoteResult(req *getVoteResultReq) ([]api.VoteInfo, error) {
+ url := "/get-vote-result"
+ payload, err := json.Marshal(req)
+ if err != nil {
+ return nil, errors.Wrap(err, "json marshal")
+ }
+ resp := []api.VoteInfo{}
+ return resp, n.request(url, payload, &resp)
+}