OSDN Git Service

add get vote result (#345)
[bytom/vapor.git] / toolbar / api_node / block.go
index a9789a2..d8a1bbf 100644 (file)
@@ -27,7 +27,29 @@ func (n *Node) getRawBlock(req *getRawBlockReq) (*types.Block, error) {
        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)
+}