Skip to content

Commit

Permalink
Rename GrinAPI to NodeAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinlesceller committed Jul 14, 2020
1 parent ef15691 commit 4e69216
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions client/node_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
"github.com/blockcypher/libgrin/core/consensus"
)

// GrinAPI struct
type GrinAPI struct {
GrinServerAPI string
// NodeAPI struct
type NodeAPI struct {
URL string
}

// GetBlockReward queries the node to get the block reward with fees
func (grinAPI *GrinAPI) GetBlockReward(blockHash string) (uint64, error) {
block, err := grinAPI.GetBlockByHash(blockHash)
func (nodeAPI *NodeAPI) GetBlockReward(blockHash string) (uint64, error) {
block, err := nodeAPI.GetBlockByHash(blockHash)
if err != nil {
return 0, err
}
Expand All @@ -43,9 +43,9 @@ func (grinAPI *GrinAPI) GetBlockReward(blockHash string) (uint64, error) {
}

// GetBlockByHash returns a block using the hash
func (grinAPI *GrinAPI) GetBlockByHash(blockHash string) (*api.BlockPrintable, error) {
func (nodeAPI *NodeAPI) GetBlockByHash(blockHash string) (*api.BlockPrintable, error) {
var block api.BlockPrintable
url := "http://" + grinAPI.GrinServerAPI + "/v1/blocks/" + blockHash
url := "http://" + nodeAPI.URL + "/v1/blocks/" + blockHash
if err := getJSON(url, &block); err != nil {
return nil, err
}
Expand All @@ -59,9 +59,9 @@ func (grinAPI *GrinAPI) GetBlockByHash(blockHash string) (*api.BlockPrintable, e
}

// GetBlockByHeight returns a block using the height
func (grinAPI *GrinAPI) GetBlockByHeight(height uint64) (*api.BlockPrintable, error) {
func (nodeAPI *NodeAPI) GetBlockByHeight(height uint64) (*api.BlockPrintable, error) {
var block api.BlockPrintable
url := fmt.Sprintf("http://%s/v1/blocks/%d", grinAPI.GrinServerAPI, height)
url := fmt.Sprintf("http://%s/v1/blocks/%d", nodeAPI.URL, height)
if err := getJSON(url, &block); err != nil {
return nil, err
}
Expand All @@ -75,9 +75,9 @@ func (grinAPI *GrinAPI) GetBlockByHeight(height uint64) (*api.BlockPrintable, er
}

// GetStatus returns the node status
func (grinAPI *GrinAPI) GetStatus() (*api.Status, error) {
func (nodeAPI *NodeAPI) GetStatus() (*api.Status, error) {
var status api.Status
url := "http://" + grinAPI.GrinServerAPI + "/v1/status"
url := "http://" + nodeAPI.URL + "/v1/status"
if err := getJSON(url, &status); err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions client/node_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ func addBlock() {
blocks = append(blocks, block16112)
}

func nextAPI(increment int) (client.GrinAPI, string) {
func nextAPI(increment int) (client.NodeAPI, string) {
var startPort = 23413
portInt := startPort + increment
port := strconv.Itoa(portInt)
addr := "127.0.0.1:" + port
return client.GrinAPI{GrinServerAPI: addr}, addr
return client.NodeAPI{URL: addr}, addr
}

// The API used here
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestGetBlockByHashMissing(t *testing.T) {
}

func TestGetBlockByHashUnreachable(t *testing.T) {
grinAPI := client.GrinAPI{}
grinAPI := client.NodeAPI{}
var blockHash = "0822cd711993d0f9a3ffdb4e755defd84a40aa25ce72f8053fa330247a36f687"
block, err := grinAPI.GetBlockByHash(blockHash)
assert.Error(t, err)
Expand All @@ -197,7 +197,7 @@ func TestGetBlockByHeightMissing(t *testing.T) {
}

func TestGetBlockUnreachable(t *testing.T) {
grinAPI := client.GrinAPI{}
grinAPI := client.NodeAPI{}
block, err := grinAPI.GetBlockByHeight(1619)
assert.Error(t, err)
assert.Nil(t, block)
Expand All @@ -218,7 +218,7 @@ func TestGetStatus(t *testing.T) {
}

func TestGetStatusUnreachable(t *testing.T) {
grinAPI := client.GrinAPI{}
grinAPI := client.NodeAPI{}
status, err := grinAPI.GetStatus()
assert.Error(t, err)
assert.Nil(t, status)
Expand Down

0 comments on commit 4e69216

Please sign in to comment.