From a6d23ae24668181a7e7c10bf9d1e741bbffe6509 Mon Sep 17 00:00:00 2001 From: Kay Date: Tue, 9 Jan 2024 13:34:19 +0000 Subject: [PATCH] fix: get time after gRPC request --- discord/discord.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/discord/discord.go b/discord/discord.go index 75619a47..8cf52cd4 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -269,19 +269,32 @@ func (b *Bot) messageHandler(s *discordgo.Session, m *discordgo.MessageCreate) { results := []Result{} - for i := 0; i < 2030; i++ { - val, err := b.cm.GetValidatorInfoByNumber(int32(i)) - if err != nil { - continue + + info, err := b.cm.GetNetworkInfo() + if err != nil { + msg := "error getting network info" + _, _ = s.ChannelMessageSendReply(m.ChannelID, msg, m.Reference()) + return + } + + for _, p := range info.ConnectedPeers { + r := Result{} + r.Agent = p.Agent + r.RemoteAddress = p.Address + r.IsActive = true + if p.Height < 673_000 { + r.IsActive = false } - result := Result{ - ValidatorAddress: val.Validator.Address, - PIP19Score: val.Validator.AvailabilityScore, + for _, v := range p.ConsensusKeys { + val, err := b.cm.GetValidatorInfo(v) + if err != nil { + continue + } + r.PIP19Score = val.Validator.AvailabilityScore + r.ValidatorAddress = v + + results = append(results, r) } - - results = append(results, result) - total += 1 - scoresSum += val.Validator.AvailabilityScore } data, err := json.Marshal(results)