From 7dfbf8ff699499e2ce90501c6948ddf2e4d20109 Mon Sep 17 00:00:00 2001 From: capossele <angelocapossele@gmail.com> Date: Fri, 17 Apr 2020 10:20:59 +0100 Subject: [PATCH] :sparkles: adds api /info --- pluginmgr/webapi/plugins.go | 2 ++ plugins/drng/drng.go | 4 ++-- plugins/webapi/info/plugin.go | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 plugins/webapi/info/plugin.go diff --git a/pluginmgr/webapi/plugins.go b/pluginmgr/webapi/plugins.go index 6299901d..76f1df75 100644 --- a/pluginmgr/webapi/plugins.go +++ b/pluginmgr/webapi/plugins.go @@ -5,6 +5,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/webapi/autopeering" "github.com/iotaledger/goshimmer/plugins/webapi/data" "github.com/iotaledger/goshimmer/plugins/webapi/drng" + "github.com/iotaledger/goshimmer/plugins/webapi/info" "github.com/iotaledger/goshimmer/plugins/webapi/message" "github.com/iotaledger/goshimmer/plugins/webapi/spammer" "github.com/iotaledger/goshimmer/plugins/webauth" @@ -19,4 +20,5 @@ var PLUGINS = node.Plugins( drng.PLUGIN, message.PLUGIN, autopeering.PLUGIN, + info.PLUGIN, ) diff --git a/plugins/drng/drng.go b/plugins/drng/drng.go index 1f4385d3..1af62582 100644 --- a/plugins/drng/drng.go +++ b/plugins/drng/drng.go @@ -1,7 +1,7 @@ package drng import ( - "encoding/base64" + "encoding/hex" "errors" "fmt" @@ -20,7 +20,7 @@ func parseCommitteeMembers() (result []ed25519.PublicKey, err error) { continue } - pubKey, err := base64.StdEncoding.DecodeString(committeeMember) + pubKey, err := hex.DecodeString(committeeMember) if err != nil { return nil, fmt.Errorf("%w: invalid public key: %s", ErrParsingCommitteeMember, err) } diff --git a/plugins/webapi/info/plugin.go b/plugins/webapi/info/plugin.go new file mode 100644 index 00000000..13eaf5e1 --- /dev/null +++ b/plugins/webapi/info/plugin.go @@ -0,0 +1,27 @@ +package info + +import ( + "encoding/hex" + "net/http" + + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/goshimmer/plugins/webapi" + "github.com/iotaledger/hive.go/node" + "github.com/labstack/echo" +) + +var PLUGIN = node.NewPlugin("WebAPI info Endpoint", node.Enabled, configure) + +func configure(plugin *node.Plugin) { + webapi.Server.GET("info", getInfo) +} + +// getInfo returns the info of the node +func getInfo(c echo.Context) error { + return c.JSON(http.StatusOK, Response{PublicKey: hex.EncodeToString(local.GetInstance().PublicKey().Bytes())}) +} + +type Response struct { + PublicKey string `json:"publickey,omitempty"` + Error string `json:"error,omitempty"` +} -- GitLab