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")
31 resp := &api.GetRawBlockResp{}
32 return resp.RawBlock, n.request(url, payload, resp)