• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revision82a133a6103353765dd0612eedc8789fb12f5a98 (tree)
Time2019-07-24 15:07:22
Authoroys <oys@oysd...>
Commiteroys

Log Message

Merge branch 'master' into dev-test

Change Summary

Incremental Difference

--- a/api/bbft.go
+++ b/api/bbft.go
@@ -6,12 +6,12 @@ import (
66 chainjson "github.com/vapor/encoding/json"
77 )
88
9-type voteInfo struct {
9+type VoteInfo struct {
1010 Vote string `json:"vote"`
1111 VoteNum uint64 `json:"vote_number"`
1212 }
1313
14-type voteInfoSlice []*voteInfo
14+type voteInfoSlice []*VoteInfo
1515
1616 func (v voteInfoSlice) Len() int { return len(v) }
1717 func (v voteInfoSlice) Less(i, j int) bool { return v[i].VoteNum > v[j].VoteNum }
@@ -36,9 +36,9 @@ func (a *API) getVoteResult(req struct {
3636 return NewErrorResponse(err)
3737 }
3838
39- voteInfos := []*voteInfo{}
39+ voteInfos := []*VoteInfo{}
4040 for pubKey, voteNum := range consensusResult.NumOfVote {
41- voteInfos = append(voteInfos, &voteInfo{
41+ voteInfos = append(voteInfos, &VoteInfo{
4242 Vote: pubKey,
4343 VoteNum: voteNum,
4444 })
--- a/toolbar/api_node/block.go
+++ b/toolbar/api_node/block.go
@@ -27,7 +27,29 @@ func (n *Node) getRawBlock(req *getRawBlockReq) (*types.Block, error) {
2727 if err != nil {
2828 return nil, errors.Wrap(err, "json marshal")
2929 }
30-
3130 resp := &api.GetRawBlockResp{}
3231 return resp.RawBlock, n.request(url, payload, resp)
3332 }
33+
34+func (n *Node) GetVoteByHash(hash string) ([]api.VoteInfo, error) {
35+ return n.getVoteResult(&getVoteResultReq{BlockHash: hash})
36+}
37+
38+func (n *Node) GetVoteByHeight(height uint64) ([]api.VoteInfo, error) {
39+ return n.getVoteResult(&getVoteResultReq{BlockHeight: height})
40+}
41+
42+type getVoteResultReq struct {
43+ BlockHeight uint64 `json:"block_height"`
44+ BlockHash string `json:"block_hash"`
45+}
46+
47+func (n *Node) getVoteResult(req *getVoteResultReq) ([]api.VoteInfo, error) {
48+ url := "/get-vote-result"
49+ payload, err := json.Marshal(req)
50+ if err != nil {
51+ return nil, errors.Wrap(err, "json marshal")
52+ }
53+ resp := []api.VoteInfo{}
54+ return resp, n.request(url, payload, &resp)
55+}
Show on old repository browser