diff --git a/README.md b/README.md index b286c87..c7bffa0 100644 --- a/README.md +++ b/README.md @@ -294,7 +294,6 @@ Additionally, for the ease of using commands, you can put the following list as ``` help - Display help message status - Display nodes status -config - Display .toml config alias - Add a wallet alias aliases - List wallet aliases ``` diff --git a/pkg/config/types/chain.go b/pkg/config/types/chain.go index f839ed6..f7796e9 100644 --- a/pkg/config/types/chain.go +++ b/pkg/config/types/chain.go @@ -29,6 +29,16 @@ func (c Chains) FindByChainID(chainID string) (*Chain, bool) { return nil, false } +func (c Chains) HasChain(name string) bool { + for _, chain := range c { + if chain.Name == name { + return true + } + } + + return false +} + type Chain struct { Name string PrettyName string diff --git a/pkg/config/types/chain_test.go b/pkg/config/types/chain_test.go index 41310de..eb9d7a3 100644 --- a/pkg/config/types/chain_test.go +++ b/pkg/config/types/chain_test.go @@ -25,6 +25,17 @@ func TestChainsFindByName(t *testing.T) { require.Nil(t, chains.FindByName("name-2")) } +func TestChainsHasByName(t *testing.T) { + t.Parallel() + + chains := types.Chains{ + {Name: "name"}, + } + + require.True(t, chains.HasChain("name")) + require.False(t, chains.HasChain("name-2")) +} + func TestChainsFindByChainID(t *testing.T) { t.Parallel() diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index d9456e6..460e791 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -18,7 +18,6 @@ const ( ReporterQueryHelp ReporterQuery = "help" ReporterQueryGetAliases ReporterQuery = "get_aliases" ReporterQuerySetAlias ReporterQuery = "set_alias" - ReporterQueryGetConfig ReporterQuery = "get_config" ReporterQueryNodesStatus ReporterQuery = "nodes_status" ) diff --git a/pkg/data_fetcher/data_fetcher.go b/pkg/data_fetcher/data_fetcher.go index d6316bd..97787ee 100644 --- a/pkg/data_fetcher/data_fetcher.go +++ b/pkg/data_fetcher/data_fetcher.go @@ -75,3 +75,22 @@ func (f *DataFetcher) FindSubscriptionByReporter( return nil, false } + +func (f *DataFetcher) FindChainsByReporter( + reporterName string, +) configTypes.Chains { + chains := make(configTypes.Chains, 0) + + for _, subscription := range f.Config.Subscriptions { + if subscription.Reporter != reporterName { + continue + } + + for _, chainSubscription := range subscription.ChainSubscriptions { + chain := f.Config.Chains.FindByName(chainSubscription.Chain) + chains = append(chains, chain) + } + } + + return chains +} diff --git a/pkg/data_fetcher/populate_proposal.go b/pkg/data_fetcher/populate_proposal.go new file mode 100644 index 0000000..eee5117 --- /dev/null +++ b/pkg/data_fetcher/populate_proposal.go @@ -0,0 +1 @@ +package data_fetcher diff --git a/pkg/reporters/telegram/get_config.go b/pkg/reporters/telegram/get_config.go deleted file mode 100644 index 4a512a2..0000000 --- a/pkg/reporters/telegram/get_config.go +++ /dev/null @@ -1,19 +0,0 @@ -package telegram - -import ( - "main/pkg/constants" - - tele "gopkg.in/telebot.v3" -) - -func (reporter *Reporter) HandleGetConfig(c tele.Context) error { - reporter.Logger.Info(). - Str("sender", c.Sender().Username). - Str("text", c.Text()). - Msg("Got get config query") - - reporter.MetricsManager.LogReporterQuery(reporter.Name(), constants.ReporterQueryGetConfig) - - configString := reporter.Config.GetConfigAsString() - return reporter.BotReply(c, configString) -} diff --git a/pkg/reporters/telegram/list_nodes_status.go b/pkg/reporters/telegram/list_nodes_status.go index 20dfcac..c2dd5cb 100644 --- a/pkg/reporters/telegram/list_nodes_status.go +++ b/pkg/reporters/telegram/list_nodes_status.go @@ -15,9 +15,18 @@ func (reporter *Reporter) HandleListNodesStatus(c tele.Context) error { reporter.MetricsManager.LogReporterQuery(reporter.Name(), constants.ReporterQueryNodesStatus) + chains := reporter.DataFetcher.FindChainsByReporter(reporter.Name()) + if len(chains) == 0 { + return reporter.BotReply(c, "This reporter is not linked to any chains!") + } + statuses := map[string]map[string]types.TendermintRPCStatus{} for chain, chainNodes := range reporter.NodesManager.Nodes { + if !chains.HasChain(chain) { + continue + } + statuses[chain] = map[string]types.TendermintRPCStatus{} for _, node := range chainNodes { statuses[chain][node.URL] = node.Status() diff --git a/pkg/reporters/telegram/telegram.go b/pkg/reporters/telegram/telegram.go index 676e3d6..6043f94 100644 --- a/pkg/reporters/telegram/telegram.go +++ b/pkg/reporters/telegram/telegram.go @@ -98,7 +98,6 @@ func (reporter *Reporter) Init() { bot.Handle("/help", reporter.HandleHelp) bot.Handle("/start", reporter.HandleHelp) bot.Handle("/status", reporter.HandleListNodesStatus) - bot.Handle("/config", reporter.HandleGetConfig) bot.Handle("/alias", reporter.HandleSetAlias) bot.Handle("/aliases", reporter.HandleGetAliases) diff --git a/pkg/types/data_fetcher.go b/pkg/types/data_fetcher.go index e6bce9e..1ddd241 100644 --- a/pkg/types/data_fetcher.go +++ b/pkg/types/data_fetcher.go @@ -51,4 +51,7 @@ type DataFetcher interface { chain *configTypes.Chain, validatorLink *configTypes.Link, ) + FindChainsByReporter( + reporterName string, + ) configTypes.Chains }