OSDN Git Service

add net info (#548)
[bytom/vapor.git] / toolbar / federation / service / node.go
index 3817288..48aac54 100644 (file)
@@ -3,9 +3,10 @@ package service
 import (
        "encoding/json"
 
-       "github.com/vapor/errors"
-       "github.com/vapor/toolbar/federation/util"
-       "github.com/vapor/protocol/bc"
+       "github.com/bytom/vapor/api"
+       "github.com/bytom/vapor/errors"
+       "github.com/bytom/vapor/protocol/bc"
+       "github.com/bytom/vapor/toolbar/common"
 )
 
 // Node can invoke the api which provide by the full node server
@@ -13,7 +14,7 @@ type Node struct {
        hostPort string
 }
 
-// Node create a api client with target server
+// NewNode create a api client with target server
 func NewNode(hostPort string) *Node {
        return &Node{hostPort: hostPort}
 }
@@ -36,6 +37,12 @@ func (n *Node) GetBlockCount() (uint64, error) {
        return res.BlockCount, n.request(url, nil, res)
 }
 
+func (n *Node) GetNetInfo() (*api.NetInfo, error) {
+       url := "/net-info"
+       res := &api.NetInfo{}
+       return res, n.request(url, nil, res)
+}
+
 type getRawBlockReq struct {
        BlockHeight uint64 `json:"block_height"`
        BlockHash   string `json:"block_hash"`
@@ -66,7 +73,7 @@ type response struct {
 
 func (n *Node) request(path string, payload []byte, respData interface{}) error {
        resp := &response{}
-       if err := util.Post(n.hostPort+path, payload, resp); err != nil {
+       if err := common.Post(n.hostPort+path, payload, resp); err != nil {
                return err
        }