OSDN Git Service

add util
[bytom/vapor.git] / toolbar / common / service / node.go
index 9b5a856..fb8a4c4 100644 (file)
@@ -3,8 +3,8 @@ package service
 import (
        "encoding/json"
 
+       "github.com/vapor/api"
        "github.com/vapor/errors"
-       "github.com/vapor/protocol/bc"
        "github.com/vapor/toolbar/common"
 )
 
@@ -18,11 +18,11 @@ func NewNode(hostPort string) *Node {
        return &Node{hostPort: hostPort}
 }
 
-func (n *Node) GetBlockByHash(hash string) (string, *bc.TransactionStatus, error) {
+func (n *Node) GetBlockByHash(hash string) (*api.GetRawBlockResp, error) {
        return n.getRawBlock(&getRawBlockReq{BlockHash: hash})
 }
 
-func (n *Node) GetBlockByHeight(height uint64) (string, *bc.TransactionStatus, error) {
+func (n *Node) GetBlockByHeight(height uint64) (*api.GetRawBlockResp, error) {
        return n.getRawBlock(&getRawBlockReq{BlockHeight: height})
 }
 
@@ -41,21 +41,15 @@ type getRawBlockReq struct {
        BlockHash   string `json:"block_hash"`
 }
 
-type getRawBlockResp struct {
-       RawBlock string `json:"raw_block"`
-       // TransactionStatus has same marshalling rule for both bytom and vapor
-       TransactionStatus *bc.TransactionStatus `json:"transaction_status"`
-}
-
-func (n *Node) getRawBlock(req *getRawBlockReq) (string, *bc.TransactionStatus, error) {
+func (n *Node) getRawBlock(req *getRawBlockReq) (*api.GetRawBlockResp, error) {
        url := "/get-raw-block"
        payload, err := json.Marshal(req)
        if err != nil {
-               return "", nil, errors.Wrap(err, "json marshal")
+               return nil, errors.Wrap(err, "json marshal")
        }
 
-       res := &getRawBlockResp{}
-       return res.RawBlock, res.TransactionStatus, n.request(url, payload, res)
+       resp := &api.GetRawBlockResp{}
+       return resp, n.request(url, payload, resp)
 }
 
 type response struct {