7 "github.com/vapor/errors"
8 "github.com/vapor/protocol/bc/types"
11 func (n *Node) GetBlockByHash(hash string) (*types.Block, error) {
12 return n.getRawBlock(&getRawBlockReq{BlockHash: hash})
15 func (n *Node) GetBlockByHeight(height uint64) (*types.Block, error) {
16 return n.getRawBlock(&getRawBlockReq{BlockHeight: height})
19 type getRawBlockReq struct {
20 BlockHeight uint64 `json:"block_height"`
21 BlockHash string `json:"block_hash"`
24 func (n *Node) getRawBlock(req *getRawBlockReq) (*types.Block, error) {
25 url := "/get-raw-block"
26 payload, err := json.Marshal(req)
28 return nil, errors.Wrap(err, "json marshal")
30 resp := &api.GetRawBlockResp{}
31 return resp.RawBlock, n.request(url, payload, resp)
34 func (n *Node) GetVoteByHash(hash string) ([]*api.VoteInfo, error) {
35 return n.getVoteResult(&getVoteResultReq{BlockHash: hash})
38 func (n *Node) GetVoteByHeight(height uint64) ([]*api.VoteInfo, error) {
39 return n.getVoteResult(&getVoteResultReq{BlockHeight: height})
42 type getVoteResultReq struct {
43 BlockHeight uint64 `json:"block_height"`
44 BlockHash string `json:"block_hash"`
47 func (n *Node) getVoteResult(req *getVoteResultReq) ([]*api.VoteInfo, error) {
48 url := "/get-vote-result"
49 payload, err := json.Marshal(req)
51 return nil, errors.Wrap(err, "json marshal")
53 resp := []*api.VoteInfo{}
54 return resp, n.request(url, payload, &resp)