Skip to content
Snippets Groups Projects
Commit 0bf75024 authored by capossele's avatar capossele
Browse files

:recycle: refactors client lib and relay-checker

parent c31c2e5d
No related branches found
No related tags found
No related merge requests found
// Implements a very simple wrapper for GoShimmer's web API . // Implements a very simple wrapper for GoShimmer's web API .
package goshimmer package client
import ( import (
"bytes" "bytes"
...@@ -11,16 +11,10 @@ import ( ...@@ -11,16 +11,10 @@ import (
"net/http" "net/http"
webapi_broadcastData "github.com/iotaledger/goshimmer/plugins/webapi/broadcastData" webapi_broadcastData "github.com/iotaledger/goshimmer/plugins/webapi/broadcastData"
webapi_findTransactionHashes "github.com/iotaledger/goshimmer/plugins/webapi/findTransactionHashes" webapi_findMessageById "github.com/iotaledger/goshimmer/plugins/webapi/findMessageById"
webapi_getNeighbors "github.com/iotaledger/goshimmer/plugins/webapi/getNeighbors" webapi_getNeighbors "github.com/iotaledger/goshimmer/plugins/webapi/getNeighbors"
webapi_getTransactionObjectsByHash "github.com/iotaledger/goshimmer/plugins/webapi/getTransactionObjectsByHash"
webapi_getTransactionTrytesByHash "github.com/iotaledger/goshimmer/plugins/webapi/getTransactionTrytesByHash"
webapi_gtta "github.com/iotaledger/goshimmer/plugins/webapi/gtta"
webapi_spammer "github.com/iotaledger/goshimmer/plugins/webapi/spammer" webapi_spammer "github.com/iotaledger/goshimmer/plugins/webapi/spammer"
webapi_auth "github.com/iotaledger/goshimmer/plugins/webauth" webapi_auth "github.com/iotaledger/goshimmer/plugins/webauth"
"github.com/iotaledger/iota.go/consts"
"github.com/iotaledger/iota.go/guards"
"github.com/iotaledger/iota.go/trinary"
) )
var ( var (
...@@ -33,14 +27,12 @@ var ( ...@@ -33,14 +27,12 @@ var (
) )
const ( const (
routeBroadcastData = "broadcastData" routeBroadcastData = "broadcastData"
routeGetTransactionTrytesByHash = "getTransactionTrytesByHash" routeGetMessageById = "getMessageById"
routeGetTransactionObjectsByHash = "getTransactionObjectsByHash" routeGetNeighbors = "getNeighbors"
routeFindTransactionsHashes = "findTransactionHashes" routeSpammer = "spammer"
routeGetNeighbors = "getNeighbors" routeLogin = "login"
routeGetTransactionsToApprove = "getTransactionsToApprove" //routeGetTransactionsToApprove = "getTransactionsToApprove"
routeSpammer = "spammer"
routeLogin = "login"
contentTypeJSON = "application/json" contentTypeJSON = "application/json"
) )
...@@ -156,68 +148,31 @@ func (api *GoShimmerAPI) Login(username string, password string) error { ...@@ -156,68 +148,31 @@ func (api *GoShimmerAPI) Login(username string, password string) error {
} }
// BroadcastData sends the given data by creating a zero value transaction in the backend targeting the given address. // BroadcastData sends the given data by creating a zero value transaction in the backend targeting the given address.
func (api *GoShimmerAPI) BroadcastData(targetAddress trinary.Trytes, data string) (trinary.Hash, error) { func (api *GoShimmerAPI) BroadcastData(data []byte) (string, error) {
if !guards.IsHash(targetAddress) {
return "", fmt.Errorf("%w: invalid address: %s", consts.ErrInvalidHash, targetAddress)
}
res := &webapi_broadcastData.Response{} res := &webapi_broadcastData.Response{}
if err := api.do(http.MethodPost, routeBroadcastData, if err := api.do(http.MethodPost, routeBroadcastData,
&webapi_broadcastData.Request{Address: targetAddress, Data: data}, res); err != nil { &webapi_broadcastData.Request{Data: data}, res); err != nil {
return "", err return "", err
} }
return res.Hash, nil return res.Id, nil
} }
// GetTransactionTrytesByHash gets the corresponding transaction trytes given the transaction hashes. func (api *GoShimmerAPI) FindMessageById(base58EncodedIds []string) (*webapi_findMessageById.Response, error) {
func (api *GoShimmerAPI) GetTransactionTrytesByHash(txHashes trinary.Hashes) ([]trinary.Trytes, error) { res := &webapi_findMessageById.Response{}
for _, hash := range txHashes {
if !guards.IsTrytes(hash) {
return nil, fmt.Errorf("%w: invalid hash: %s", consts.ErrInvalidHash, hash)
}
}
res := &webapi_getTransactionTrytesByHash.Response{} err := api.do(
if err := api.do(http.MethodPost, routeGetTransactionTrytesByHash, http.MethodPost,
&webapi_getTransactionTrytesByHash.Request{Hashes: txHashes}, res); err != nil { routeGetMessageById,
return nil, err &webapi_findMessageById.Request{Ids: base58EncodedIds},
} res,
)
return res.Trytes, nil if err != nil {
}
// GetTransactionObjectsByHash gets the transaction objects given the transaction hashes.
func (api *GoShimmerAPI) GetTransactionObjectsByHash(txHashes trinary.Hashes) ([]webapi_getTransactionObjectsByHash.Transaction, error) {
for _, hash := range txHashes {
if !guards.IsTrytes(hash) {
return nil, fmt.Errorf("%w: invalid hash: %s", consts.ErrInvalidHash, hash)
}
}
res := &webapi_getTransactionObjectsByHash.Response{}
if err := api.do(http.MethodPost, routeGetTransactionObjectsByHash,
&webapi_getTransactionObjectsByHash.Request{Hashes: txHashes}, res); err != nil {
return nil, err
}
return res.Transactions, nil
}
// FindTransactionHashes finds the given transaction hashes given the query.
func (api *GoShimmerAPI) FindTransactionHashes(query *webapi_findTransactionHashes.Request) ([]trinary.Hashes, error) {
for _, hash := range query.Addresses {
if !guards.IsTrytes(hash) {
return nil, fmt.Errorf("%w: invalid hash: %s", consts.ErrInvalidHash, hash)
}
}
res := &webapi_findTransactionHashes.Response{}
if err := api.do(http.MethodPost, routeFindTransactionsHashes, query, res); err != nil {
return nil, err return nil, err
} }
return res.Transactions, nil return res, nil
} }
// GetNeighbors gets the chosen/accepted neighbors. // GetNeighbors gets the chosen/accepted neighbors.
...@@ -235,14 +190,14 @@ func (api *GoShimmerAPI) GetNeighbors(knownPeers bool) (*webapi_getNeighbors.Res ...@@ -235,14 +190,14 @@ func (api *GoShimmerAPI) GetNeighbors(knownPeers bool) (*webapi_getNeighbors.Res
return res, nil return res, nil
} }
// GetTips executes the tip-selection on the node to retrieve tips to approve. // // GetTips executes the tip-selection on the node to retrieve tips to approve.
func (api *GoShimmerAPI) GetTransactionsToApprove() (*webapi_gtta.Response, error) { // func (api *GoShimmerAPI) GetTransactionsToApprove() (*webapi_gtta.Response, error) {
res := &webapi_gtta.Response{} // res := &webapi_gtta.Response{}
if err := api.do(http.MethodGet, routeGetTransactionsToApprove, nil, res); err != nil { // if err := api.do(http.MethodGet, routeGetTransactionsToApprove, nil, res); err != nil {
return nil, err // return nil, err
} // }
return res, nil // return res, nil
} // }
// ToggleSpammer toggles the node internal spammer. // ToggleSpammer toggles the node internal spammer.
func (api *GoShimmerAPI) ToggleSpammer(enable bool) (*webapi_spammer.Response, error) { func (api *GoShimmerAPI) ToggleSpammer(enable bool) (*webapi_spammer.Response, error) {
......
...@@ -3,11 +3,8 @@ package webapi ...@@ -3,11 +3,8 @@ package webapi
import ( import (
"github.com/iotaledger/goshimmer/plugins/webapi" "github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/iotaledger/goshimmer/plugins/webapi/broadcastData" "github.com/iotaledger/goshimmer/plugins/webapi/broadcastData"
"github.com/iotaledger/goshimmer/plugins/webapi/findTransactionHashes" "github.com/iotaledger/goshimmer/plugins/webapi/findMessageById"
"github.com/iotaledger/goshimmer/plugins/webapi/getNeighbors" "github.com/iotaledger/goshimmer/plugins/webapi/getNeighbors"
"github.com/iotaledger/goshimmer/plugins/webapi/getTransactionObjectsByHash"
"github.com/iotaledger/goshimmer/plugins/webapi/getTransactionTrytesByHash"
"github.com/iotaledger/goshimmer/plugins/webapi/gtta"
"github.com/iotaledger/goshimmer/plugins/webapi/spammer" "github.com/iotaledger/goshimmer/plugins/webapi/spammer"
"github.com/iotaledger/goshimmer/plugins/webauth" "github.com/iotaledger/goshimmer/plugins/webauth"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
...@@ -16,11 +13,9 @@ import ( ...@@ -16,11 +13,9 @@ import (
var PLUGINS = node.Plugins( var PLUGINS = node.Plugins(
webapi.PLUGIN, webapi.PLUGIN,
webauth.PLUGIN, webauth.PLUGIN,
gtta.PLUGIN, //gtta.PLUGIN,
spammer.PLUGIN, spammer.PLUGIN,
broadcastData.PLUGIN, broadcastData.PLUGIN,
getTransactionTrytesByHash.PLUGIN, findMessageById.PLUGIN,
getTransactionObjectsByHash.PLUGIN,
findTransactionHashes.PLUGIN,
getNeighbors.PLUGIN, getNeighbors.PLUGIN,
) )
...@@ -19,8 +19,8 @@ func configure(plugin *node.Plugin) { ...@@ -19,8 +19,8 @@ func configure(plugin *node.Plugin) {
webapi.Server.POST("broadcastData", broadcastData) webapi.Server.POST("broadcastData", broadcastData)
} }
// broadcastData creates a data (0-value) transaction given an input of bytes and // broadcastData creates a message of the given payload and
// broadcasts it to the node's neighbors. It returns the transaction hash if successful. // broadcasts it to the node's neighbors. It returns the message ID if successful.
func broadcastData(c echo.Context) error { func broadcastData(c echo.Context) error {
var request Request var request Request
if err := c.Bind(&request); err != nil { if err := c.Bind(&request); err != nil {
...@@ -28,17 +28,18 @@ func broadcastData(c echo.Context) error { ...@@ -28,17 +28,18 @@ func broadcastData(c echo.Context) error {
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()}) return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
} }
tx := messagelayer.MessageFactory.IssuePayload(payload.NewData([]byte(request.Data))) //TODO: to check max payload size allowed, if exceeding return an error
return c.JSON(http.StatusOK, Response{Hash: tx.Id().String()}) tx := messagelayer.MessageFactory.IssuePayload(payload.NewData(request.Data))
return c.JSON(http.StatusOK, Response{Id: tx.Id().String()})
} }
type Response struct { type Response struct {
Hash string `json:"hash,omitempty"` Id string `json:"id,omitempty"`
Error string `json:"error,omitempty"` Error string `json:"error,omitempty"`
} }
type Request struct { type Request struct {
Address string `json:"address"` Data []byte `json:"data"`
Data string `json:"data"`
} }
package findMessageById
import (
"net/http"
"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
"github.com/iotaledger/goshimmer/plugins/messagelayer"
"github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/labstack/echo"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
)
var PLUGIN = node.NewPlugin("WebAPI findMessageById Endpoint", node.Enabled, configure)
var log *logger.Logger
func configure(plugin *node.Plugin) {
log = logger.NewLogger("API-findMessageById")
webapi.Server.POST("findMessageById", findMessageById)
}
// getMessageByHash returns the array of messages for the
// given message ids (MUST be encoded in base58), in the same order as the parameters.
// If a node doesn't have the message for a given ID in its ledger,
// the value at the index of that message ID is empty.
func findMessageById(c echo.Context) error {
var request Request
if err := c.Bind(&request); err != nil {
log.Info(err.Error())
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
var result []Message
for _, id := range request.Ids {
log.Info("Received:", id)
msgId, err := message.NewId(id)
if err != nil {
log.Info(err)
continue
}
msgObject := messagelayer.Tangle.Message(msgId)
if !msgObject.Exists() {
continue
}
msg := msgObject.Unwrap()
msgResp := Message{
Id: msg.Id().String(),
TrunkId: msg.TrunkId().String(),
BranchId: msg.BranchId().String(),
IssuerPublicKey: msg.IssuerPublicKey().String(),
IssuingTime: msg.IssuingTime().String(),
SequenceNumber: msg.SequenceNumber(),
Payload: msg.Payload().Bytes(),
Signature: msg.Signature().String(),
}
result = append(result, msgResp)
msgObject.Release()
}
return c.JSON(http.StatusOK, Response{Messages: result})
}
type Response struct {
Messages []Message `json:"messages,omitempty"`
Error string `json:"error,omitempty"`
}
type Request struct {
Ids []string `json:"ids"`
}
type Message struct {
Id string `json:"Id,omitempty"`
TrunkId string `json:"trunkId,omitempty"`
BranchId string `json:"branchId,omitempty"`
IssuerPublicKey string `json:"issuerPublicKey,omitempty"`
IssuingTime string `json:"issuingTime,omitempty"`
SequenceNumber uint64 `json:"sequenceNumber,omitempty"`
Payload []byte `json:"payload,omitempty"`
Signature string `json:"signature,omitempty"`
}
package findTransactionHashes
import (
"net/http"
"github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/iota.go/trinary"
"github.com/labstack/echo"
)
var PLUGIN = node.NewPlugin("WebAPI findTransactionHashes Endpoint", node.Enabled, configure)
var log *logger.Logger
func configure(plugin *node.Plugin) {
log = logger.NewLogger("API-findTransactionHashes")
webapi.Server.POST("findTransactionHashes", findTransactionHashes)
}
// findTransactionHashes returns the array of transaction hashes for the
// given addresses (in the same order as the parameters).
// If a node doesn't have any transaction hash for a given address in its ledger,
// the value at the index of that address is empty.
func findTransactionHashes(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, Response{Error: "TODO: ADD LOGIC ACCORDING TO VALUE TANGLE"})
// TODO: ADD LOGIC ACCORDING TO VALUE TANGLE
/*
var request Request
if err := c.Bind(&request); err != nil {
log.Info(err.Error())
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
log.Debug("Received:", request.Addresses)
result := make([][]trinary.Trytes, len(request.Addresses))
for i, address := range request.Addresses {
txs, err := tangle_old.ReadTransactionHashesForAddressFromDatabase(address)
if err != nil {
return c.JSON(http.StatusInternalServerError, Response{Error: err.Error()})
}
result[i] = append(result[i], txs...)
}
return c.JSON(http.StatusOK, Response{Transactions: result})
*/
}
type Response struct {
Transactions [][]trinary.Trytes `json:"transactions,omitempty"` //string
Error string `json:"error,omitempty"`
}
type Request struct {
Addresses []string `json:"addresses"`
}
package getTransactionObjectsByHash
import (
"net/http"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/iota.go/trinary"
"github.com/labstack/echo"
"github.com/iotaledger/goshimmer/plugins/webapi"
)
var PLUGIN = node.NewPlugin("WebAPI getTransactionObjectsByHash Endpoint", node.Enabled, configure)
var log *logger.Logger
func configure(plugin *node.Plugin) {
log = logger.NewLogger("API-getTransactionObjectsByHash")
webapi.Server.POST("getTransactionObjectsByHash", getTransactionObjectsByHash)
}
// getTransactionObjectsByHash returns the array of transactions for the
// given transaction hashes (in the same order as the parameters).
// If a node doesn't have the transaction for a given transaction hash in its ledger,
// the value at the index of that transaction hash is empty.
func getTransactionObjectsByHash(c echo.Context) error {
var request Request
result := []Transaction{}
if err := c.Bind(&request); err != nil {
log.Info(err.Error())
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
log.Debug("Received:", request.Hashes)
/*
for _, hash := range request.Hashes {
tx, err := tangle_old.GetTransaction(hash)
if err != nil {
return c.JSON(http.StatusInternalServerError, Response{Error: err.Error()})
}
if tx == nil {
return c.JSON(http.StatusNotFound, Response{Error: fmt.Sprintf("transaction not found: %s", hash)})
}
t := Transaction{
Hash: tx.GetHash(),
WeightMagnitude: tx.GetWeightMagnitude(),
TrunkTransactionHash: tx.GetTrunkTransactionHash(),
BranchTransactionHash: tx.GetBranchTransactionHash(),
Head: tx.IsHead(),
Tail: tx.IsTail(),
Nonce: tx.GetNonce(),
Address: tx.GetAddress(),
Value: tx.GetValue(),
Timestamp: tx.GetTimestamp(),
SignatureMessageFragment: tx.GetSignatureMessageFragment(),
}
result = append(result, t)
}
*/
return c.JSON(http.StatusOK, Response{Transactions: result})
}
type Response struct {
Transactions []Transaction `json:"transaction,omitempty"`
Error string `json:"error,omitempty"`
}
type Request struct {
Hashes []string `json:"hashes"`
}
type Transaction struct {
Hash trinary.Trytes `json:"hash,omitempty"`
WeightMagnitude int `json:"weightMagnitude,omitempty"`
TrunkTransactionHash trinary.Trytes `json:"trunkTransactionHash,omitempty"`
BranchTransactionHash trinary.Trytes `json:"branchTransactionHash,omitempty"`
Head bool `json:"head,omitempty"`
Tail bool `json:"tail,omitempty"`
Nonce trinary.Trytes `json:"nonce,omitempty"`
Address trinary.Trytes `json:"address,omitempty"`
Value int64 `json:"value,omitempty"`
Timestamp uint `json:"timestamp,omitempty"`
SignatureMessageFragment trinary.Trytes `json:"signatureMessageFragment,omitempty"`
}
package getTransactionTrytesByHash
import (
"net/http"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/iotaledger/iota.go/trinary"
"github.com/labstack/echo"
"github.com/iotaledger/goshimmer/plugins/webapi"
)
var PLUGIN = node.NewPlugin("WebAPI getTransactionTrytesByHash Endpoint", node.Enabled, configure)
var log *logger.Logger
func configure(plugin *node.Plugin) {
log = logger.NewLogger("API-getTransactionTrytesByHash")
webapi.Server.POST("getTransactionTrytesByHash", getTransactionTrytesByHash)
}
// getTransactionTrytesByHash returns the array of transaction trytes for the
// given transaction hashes (in the same order as the parameters).
// If a node doesn't have the trytes for a given transaction hash in its ledger,
// the value at the index of that transaction hash is empty.
func getTransactionTrytesByHash(c echo.Context) error {
var request Request
result := []trinary.Trytes{}
if err := c.Bind(&request); err != nil {
log.Info(err.Error())
return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
}
log.Debug("Received:", request.Hashes)
/*
for _, hash := range request.Hashes {
tx, err := tangle_old.GetTransaction(hash)
if err != nil {
return c.JSON(http.StatusInternalServerError, Response{Error: err.Error()})
}
if tx == nil {
return c.JSON(http.StatusNotFound, Response{Error: fmt.Sprintf("transaction not found: %s", hash)})
}
trytes := trinary.MustTritsToTrytes(tx.GetTrits())
result = append(result, trytes)
}
*/
return c.JSON(http.StatusOK, Response{Trytes: result})
}
type Response struct {
Trytes []trinary.Trytes `json:"trytes,omitempty"` //string
Error string `json:"error,omitempty"`
}
type Request struct {
Hashes []string `json:"hashes"`
}
...@@ -5,8 +5,7 @@ import "github.com/iotaledger/goshimmer/plugins/config" ...@@ -5,8 +5,7 @@ import "github.com/iotaledger/goshimmer/plugins/config"
var ( var (
nodes []string nodes []string
target = "" target = ""
txnAddr = "GOSHIMMER99TEST999999999999999999999999999999999999999999999999999999999999999999" msgData = "TEST99BROADCAST99DATA"
txnData = "TEST99BROADCAST99DATA"
cooldownTime = 2 cooldownTime = 2
repeat = 1 repeat = 1
) )
...@@ -23,11 +22,8 @@ func InitConfig() { ...@@ -23,11 +22,8 @@ func InitConfig() {
nodes = append(nodes, config.Node.GetStringSlice(CFG_TEST_NODES)...) nodes = append(nodes, config.Node.GetStringSlice(CFG_TEST_NODES)...)
// optional settings // optional settings
if config.Node.GetString(CFG_TX_ADDRESS) != "" {
txnAddr = config.Node.GetString(CFG_TX_ADDRESS)
}
if config.Node.GetString(CFG_DATA) != "" { if config.Node.GetString(CFG_DATA) != "" {
txnData = config.Node.GetString(CFG_DATA) msgData = config.Node.GetString(CFG_DATA)
} }
if config.Node.GetInt(CFG_COOLDOWN_TIME) > 0 { if config.Node.GetInt(CFG_COOLDOWN_TIME) > 0 {
cooldownTime = config.Node.GetInt(CFG_COOLDOWN_TIME) cooldownTime = config.Node.GetInt(CFG_COOLDOWN_TIME)
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
"testNodes": [ "testNodes": [
"http://127.0.0.1:8080" "http://127.0.0.1:8080"
], ],
"txAddress": "SHIMMER99TEST99999999999999999999999999999999999999999999999999999999999999999999",
"data": "TEST99BROADCAST99DATA", "data": "TEST99BROADCAST99DATA",
"cooldownTime": 10, "cooldownTime": 10,
"repeat": 2 "repeat": 2
......
...@@ -7,34 +7,32 @@ import ( ...@@ -7,34 +7,32 @@ import (
client "github.com/iotaledger/goshimmer/client" client "github.com/iotaledger/goshimmer/client"
"github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/logger" "github.com/iotaledger/goshimmer/plugins/logger"
"github.com/iotaledger/iota.go/trinary"
) )
func testBroadcastData(api *client.GoShimmerAPI) (trinary.Hash, error) { func testBroadcastData(api *client.GoShimmerAPI) (string, error) {
txnHash, err := api.BroadcastData(txnAddr, txnData) msgId, err := api.BroadcastData([]byte(msgData))
if err != nil { if err != nil {
return "", fmt.Errorf("broadcast failed: %w", err) return "", fmt.Errorf("broadcast failed: %w", err)
} }
return txnHash, nil return msgId, nil
} }
func testTargetGetTransactions(api *client.GoShimmerAPI, txnHash trinary.Hash) error { func testTargetGetMessagess(api *client.GoShimmerAPI, msgId string) error {
// query target node for broadcasted data // query target node for broadcasted data
if _, err := api.GetTransactionObjectsByHash([]trinary.Hash{txnHash}); err != nil { if _, err := api.FindMessageById([]string{msgId}); err != nil {
return fmt.Errorf("querying the target node failed: %w", err) return fmt.Errorf("querying the target node failed: %w", err)
} }
return nil return nil
} }
func testNodesGetTransactions(txnHash trinary.Hash) error { func testNodesGetMessages(msgId string) error {
// query nodes node for broadcasted data // query nodes node for broadcasted data
for _, n := range nodes { for _, n := range nodes {
nodesApi := client.NewGoShimmerAPI(n) nodesApi := client.NewGoShimmerAPI(n)
if _, err := nodesApi.GetTransactionObjectsByHash([]trinary.Hash{txnHash}); err != nil { if _, err := nodesApi.FindMessageById([]string{msgId}); err != nil {
return fmt.Errorf("querying node %s failed: %w", n, err) return fmt.Errorf("querying node %s failed: %w", n, err)
} }
fmt.Printf("txn found in node %s\n", n) fmt.Printf("msg found in node %s\n", n)
} }
return nil return nil
} }
...@@ -47,25 +45,25 @@ func main() { ...@@ -47,25 +45,25 @@ func main() {
api := client.NewGoShimmerAPI(target) api := client.NewGoShimmerAPI(target)
for i := 0; i < repeat; i++ { for i := 0; i < repeat; i++ {
txnHash, err := testBroadcastData(api) msgId, err := testBroadcastData(api)
if err != nil { if err != nil {
fmt.Printf("%s\n", err) fmt.Printf("%s\n", err)
break break
} }
fmt.Printf("txnHash: %s\n", txnHash) fmt.Printf("msgId: %s\n", msgId)
// cooldown time // cooldown time
time.Sleep(time.Duration(cooldownTime) * time.Second) time.Sleep(time.Duration(cooldownTime) * time.Second)
// query target node // query target node
err = testTargetGetTransactions(api, txnHash) err = testTargetGetMessagess(api, msgId)
if err != nil { if err != nil {
fmt.Printf("%s\n", err) fmt.Printf("%s\n", err)
break break
} }
// query test nodes // query test nodes
err = testNodesGetTransactions(txnHash) err = testNodesGetMessages(msgId)
if err != nil { if err != nil {
fmt.Printf("%s\n", err) fmt.Printf("%s\n", err)
break break
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
const ( const (
CFG_TARGET_NODE = "relayChecker.targetNode" CFG_TARGET_NODE = "relayChecker.targetNode"
CFG_TEST_NODES = "relayChecker.testNodes" CFG_TEST_NODES = "relayChecker.testNodes"
CFG_TX_ADDRESS = "relayChecker.txAddress"
CFG_DATA = "relayChecker.data" CFG_DATA = "relayChecker.data"
CFG_COOLDOWN_TIME = "relayChecker.cooldownTime" CFG_COOLDOWN_TIME = "relayChecker.cooldownTime"
CFG_REPEAT = "relayChecker.repeat" CFG_REPEAT = "relayChecker.repeat"
...@@ -15,8 +14,7 @@ const ( ...@@ -15,8 +14,7 @@ const (
func init() { func init() {
flag.StringSlice(CFG_TEST_NODES, []string{""}, "the list of nodes to check after the cooldown") flag.StringSlice(CFG_TEST_NODES, []string{""}, "the list of nodes to check after the cooldown")
flag.String(CFG_TARGET_NODE, "http://127.0.0.1:8080", "the target node from the which transaction will be broadcasted from") flag.String(CFG_TARGET_NODE, "http://127.0.0.1:8080", "the target node from the which message will be broadcasted from")
flag.String(CFG_TX_ADDRESS, "SHIMMER99TEST99999999999999999999999999999999999999999999999999999999999999999999", "the transaction address")
flag.String(CFG_DATA, "TEST99BROADCAST99DATA", "data to broadcast") flag.String(CFG_DATA, "TEST99BROADCAST99DATA", "data to broadcast")
flag.Int(CFG_COOLDOWN_TIME, 10, "the cooldown time after broadcasting the data on the specified target node") flag.Int(CFG_COOLDOWN_TIME, 10, "the cooldown time after broadcasting the data on the specified target node")
flag.Int(CFG_REPEAT, 1, "the amount of times to repeat the relay-checker queries") flag.Int(CFG_REPEAT, 1, "the amount of times to repeat the relay-checker queries")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment