Skip to content
Snippets Groups Projects
Unverified Commit 396392f9 authored by Luca Moser's avatar Luca Moser Committed by GitHub
Browse files

renames the client lib main struct (#122)

parent 3f7ac60e
No related branches found
No related tags found
No related merge requests found
// Implements a very simple wrapper for GoShimmer's HTTP API . // Implements a very simple wrapper for GoShimmer's HTTP API .
package shimmer package goshimmer
import ( import (
"bytes" "bytes"
...@@ -40,11 +40,11 @@ const ( ...@@ -40,11 +40,11 @@ const (
contentTypeJSON = "application/json" contentTypeJSON = "application/json"
) )
func NewShimmerAPI(node string) *ShimmerAPI { func NewGoShimmerAPI(node string) *GoShimmerAPI {
return &ShimmerAPI{node: node} return &GoShimmerAPI{node: node}
} }
type ShimmerAPI struct { type GoShimmerAPI struct {
http.Client http.Client
node string node string
} }
...@@ -80,7 +80,7 @@ func interpretBody(res *http.Response, decodeTo interface{}) error { ...@@ -80,7 +80,7 @@ func interpretBody(res *http.Response, decodeTo interface{}) error {
return errors.Wrap(ErrUnknownError, errRes.Error) return errors.Wrap(ErrUnknownError, errRes.Error)
} }
func (api *ShimmerAPI) BroadcastData(targetAddress trinary.Trytes, data trinary.Trytes) (trinary.Hash, error) { func (api *GoShimmerAPI) BroadcastData(targetAddress trinary.Trytes, data trinary.Trytes) (trinary.Hash, error) {
if !guards.IsHash(targetAddress) { if !guards.IsHash(targetAddress) {
return "", errors.Wrapf(consts.ErrInvalidHash, "invalid address: %s", targetAddress) return "", errors.Wrapf(consts.ErrInvalidHash, "invalid address: %s", targetAddress)
} }
...@@ -106,7 +106,7 @@ func (api *ShimmerAPI) BroadcastData(targetAddress trinary.Trytes, data trinary. ...@@ -106,7 +106,7 @@ func (api *ShimmerAPI) BroadcastData(targetAddress trinary.Trytes, data trinary.
return resObj.Hash, nil return resObj.Hash, nil
} }
func (api *ShimmerAPI) GetTrytes(txHashes trinary.Hashes) ([]trinary.Trytes, error) { func (api *GoShimmerAPI) GetTrytes(txHashes trinary.Hashes) ([]trinary.Trytes, error) {
for _, hash := range txHashes { for _, hash := range txHashes {
if !guards.IsTrytes(hash) { if !guards.IsTrytes(hash) {
return nil, errors.Wrapf(consts.ErrInvalidHash, "invalid hash: %s", hash) return nil, errors.Wrapf(consts.ErrInvalidHash, "invalid hash: %s", hash)
...@@ -131,7 +131,7 @@ func (api *ShimmerAPI) GetTrytes(txHashes trinary.Hashes) ([]trinary.Trytes, err ...@@ -131,7 +131,7 @@ func (api *ShimmerAPI) GetTrytes(txHashes trinary.Hashes) ([]trinary.Trytes, err
return resObj.Trytes, nil return resObj.Trytes, nil
} }
func (api *ShimmerAPI) GetTransactions(txHashes trinary.Hashes) ([]webapi_getTransactions.Transaction, error) { func (api *GoShimmerAPI) GetTransactions(txHashes trinary.Hashes) ([]webapi_getTransactions.Transaction, error) {
for _, hash := range txHashes { for _, hash := range txHashes {
if !guards.IsTrytes(hash) { if !guards.IsTrytes(hash) {
return nil, errors.Wrapf(consts.ErrInvalidHash, "invalid hash: %s", hash) return nil, errors.Wrapf(consts.ErrInvalidHash, "invalid hash: %s", hash)
...@@ -156,7 +156,7 @@ func (api *ShimmerAPI) GetTransactions(txHashes trinary.Hashes) ([]webapi_getTra ...@@ -156,7 +156,7 @@ func (api *ShimmerAPI) GetTransactions(txHashes trinary.Hashes) ([]webapi_getTra
return resObj.Transactions, nil return resObj.Transactions, nil
} }
func (api *ShimmerAPI) FindTransactions(query *webapi_findTransactions.Request) ([]trinary.Hashes, error) { func (api *GoShimmerAPI) FindTransactions(query *webapi_findTransactions.Request) ([]trinary.Hashes, error) {
for _, hash := range query.Addresses { for _, hash := range query.Addresses {
if !guards.IsTrytes(hash) { if !guards.IsTrytes(hash) {
return nil, errors.Wrapf(consts.ErrInvalidHash, "invalid hash: %s", hash) return nil, errors.Wrapf(consts.ErrInvalidHash, "invalid hash: %s", hash)
...@@ -181,7 +181,7 @@ func (api *ShimmerAPI) FindTransactions(query *webapi_findTransactions.Request) ...@@ -181,7 +181,7 @@ func (api *ShimmerAPI) FindTransactions(query *webapi_findTransactions.Request)
return resObj.Transactions, nil return resObj.Transactions, nil
} }
func (api *ShimmerAPI) GetNeighbors() (*webapi_getNeighbors.Response, error) { func (api *GoShimmerAPI) GetNeighbors() (*webapi_getNeighbors.Response, error) {
res, err := api.Get(fmt.Sprintf("%s/%s", api.node, routeGetNeighbors)) res, err := api.Get(fmt.Sprintf("%s/%s", api.node, routeGetNeighbors))
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -195,7 +195,7 @@ func (api *ShimmerAPI) GetNeighbors() (*webapi_getNeighbors.Response, error) { ...@@ -195,7 +195,7 @@ func (api *ShimmerAPI) GetNeighbors() (*webapi_getNeighbors.Response, error) {
return resObj, nil return resObj, nil
} }
func (api *ShimmerAPI) GetTips() (*webapi_gtta.Response, error) { func (api *GoShimmerAPI) GetTips() (*webapi_gtta.Response, error) {
res, err := api.Get(fmt.Sprintf("%s/%s", api.node, routeGetTransactionsToApprove)) res, err := api.Get(fmt.Sprintf("%s/%s", api.node, routeGetTransactionsToApprove))
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -209,7 +209,7 @@ func (api *ShimmerAPI) GetTips() (*webapi_gtta.Response, error) { ...@@ -209,7 +209,7 @@ func (api *ShimmerAPI) GetTips() (*webapi_gtta.Response, error) {
return resObj, nil return resObj, nil
} }
func (api *ShimmerAPI) ToggleSpammer(enable bool) (*webapi_spammer.Response, error) { func (api *GoShimmerAPI) ToggleSpammer(enable bool) (*webapi_spammer.Response, error) {
res, err := api.Get(fmt.Sprintf("%s/%s?cmd=%s", api.node, routeSpammer, func() string { res, err := api.Get(fmt.Sprintf("%s/%s?cmd=%s", api.node, routeSpammer, func() string {
if enable { if enable {
return "start" return "start"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment