diff --git a/client/info.go b/client/info.go new file mode 100644 index 0000000000000000000000000000000000000000..08c43ae6f30d4c27a235bd548f2b17c3dda061ca --- /dev/null +++ b/client/info.go @@ -0,0 +1,20 @@ +package client + +import ( + "net/http" + + webapi_info "github.com/iotaledger/goshimmer/plugins/webapi/info" +) + +const ( + routeInfo = "info" +) + +// Info gets the info of the node. +func (api *GoShimmerAPI) Info() (*webapi_info.Response, error) { + res := &webapi_info.Response{} + if err := api.do(http.MethodGet, routeInfo, nil, res); err != nil { + return nil, err + } + return res, nil +} diff --git a/pluginmgr/webapi/plugins.go b/pluginmgr/webapi/plugins.go index 6299901d87e3547c2acd8be3306522e91ad87ec6..464d058c33ddb59fe421511e5cae440a0f93698b 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 1f4385d3f477ee9e8a714c1ab91478807cd32658..7f44946f9de4f6ed79321e6f7840e097627aba7c 100644 --- a/plugins/drng/drng.go +++ b/plugins/drng/drng.go @@ -1,12 +1,12 @@ package drng import ( - "encoding/base64" "errors" "fmt" "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/hive.go/crypto/ed25519" + "github.com/mr-tron/base58/base58" ) var ( @@ -20,7 +20,7 @@ func parseCommitteeMembers() (result []ed25519.PublicKey, err error) { continue } - pubKey, err := base64.StdEncoding.DecodeString(committeeMember) + pubKey, err := base58.Decode(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 0000000000000000000000000000000000000000..e2ae0357c4e29bc264fc60072c841ff9caa30aee --- /dev/null +++ b/plugins/webapi/info/plugin.go @@ -0,0 +1,92 @@ +package info + +import ( + "net/http" + + "github.com/iotaledger/goshimmer/plugins/autopeering/local" + "github.com/iotaledger/goshimmer/plugins/banner" + "github.com/iotaledger/goshimmer/plugins/webapi" + "github.com/iotaledger/hive.go/node" + "github.com/labstack/echo" +) + +// Plugin exports the plugin +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 +// e.g., +// { +// "version":"v0.2.0", +// "identityID":"5bf4aa1d6c47e4ce", +// "publickey":"CjUsn86jpFHWnSCx3NhWfU4Lk16mDdy1Hr7ERSTv3xn9", +// "enabledplugins":[ +// "Config", +// "Autopeering", +// "Analysis", +// "WebAPI data Endpoint", +// "WebAPI dRNG Endpoint", +// "MessageLayer", +// "CLI", +// "Database", +// "DRNG", +// "WebAPI autopeering Endpoint", +// "Metrics", +// "PortCheck", +// "SPA", +// "WebAPI", +// "WebAPI info Endpoint", +// "WebAPI message Endpoint", +// "Banner", +// "Gossip", +// "Graceful Shutdown", +// "Logger" +// ], +// "disabledlugins":[ +// "Graph", +// "RemoteLog", +// "Spammer", +// "WebAPI Auth" +// ] +// } +func getInfo(c echo.Context) error { + var enabledPlugins []string + var disabledPlugins []string + for plugin, status := range node.GetPlugins() { + switch status { + case node.Disabled: + disabledPlugins = append(disabledPlugins, plugin) + case node.Enabled: + enabledPlugins = append(enabledPlugins, plugin) + default: + continue + } + } + + return c.JSON(http.StatusOK, Response{ + Version: banner.AppVersion, + IdentityID: local.GetInstance().Identity.ID().String(), + PublicKey: local.GetInstance().PublicKey().String(), + EnabledPlugins: enabledPlugins, + DisabledPlugins: disabledPlugins, + }) +} + +// Response holds the response of the GET request. +type Response struct { + // version of GoShimmer + Version string `json:"version,omitempty"` + // identity ID of the node encoded in hex and truncated to its first 8 bytes + IdentityID string `json:"identityID,omitempty"` + // public key of the node encoded in base58 + PublicKey string `json:"publickey,omitempty"` + // list of enabled plugins + EnabledPlugins []string `json:"enabledplugins,omitempty"` + // list if disabled plugins + DisabledPlugins []string `json:"disabledlugins,omitempty"` + // error of the response + Error string `json:"error,omitempty"` +}