-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
109 lines (92 loc) · 2.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"time"
client "github.com/kehiy/vv-pactus/client"
"github.com/kehiy/vv-pactus/utils"
"github.com/libp2p/go-libp2p/core/peer"
)
var (
validHeight uint32 = 600000
)
type Result struct {
ID int `json:"id"`
Address string `json:"address"`
Discord string `json:"discord"`
DiscordHide string `json:"discordhide"`
Instagram string `json:"instagram"`
InstagramHide string `json:"instagramhide"`
Twitter string `json:"twitter"`
TwitterHide string `json:"twitterhide"`
Status string `json:"status"`
PeerId string `json:"peerid"`
ValNum int32 `json:"validaornumber"`
ValSeq int32 `json:"validaorseq"`
}
func main() {
s := time.Now()
result := []Result{}
data, err := utils.ReadExcel("data.xlsx", "Form Responses 1")
if err != nil {
log.Fatalf("error reading data: %v", err)
}
c, err := client.NewClient("172.104.46.145:9090")
if err != nil {
log.Fatalf("err making client: %v", err)
}
info, err := c.GetNetworkInfo()
if err != nil {
log.Fatalf("err read network info: %v", err)
}
dup := make(map[string]int)
// check status
for _, d := range data {
r := Result{Address: d[3], Discord: d[0], Twitter: d[1], Instagram: d[2]}
var addr string
for _, inf := range info.GetPeers() {
for _, k := range inf.ConsensusKeys {
addr = utils.AddressFromPublicKey(k)
if d[3] == addr {
status := "valid"
if inf.Height < validHeight {
status = "notSynced"
}
index, ok := dup[string(inf.GetPeerId())]
if ok {
status = "duplicate"
result[index].Status = "duplicate"
} else {
dup[string(inf.GetPeerId())] = len(result)
}
r.Status = status
pid, _ := peer.IDFromBytes(inf.GetPeerId())
r.PeerId = pid.String()
r.ID = len(result) + 1
r.DiscordHide = utils.HideId(r.Discord)
r.InstagramHide = utils.HideId(r.Instagram)
r.TwitterHide = utils.HideId(r.Twitter)
validatorInfo, err := c.GetValidatorInfo(r.Address)
if err == nil {
r.ValNum = validatorInfo.Validator.Number
r.ValSeq = validatorInfo.Validator.Sequence
}
result = append(result, r)
}
}
}
}
fin, err := json.Marshal(result)
if err != nil {
log.Fatalf("err marshal result: %v", err)
}
outputFile, err := os.Create("output.json")
if err != nil {
log.Fatalf("err create file: %v", err)
}
defer outputFile.Close()
outputFile.Write([]byte(fin))
fmt.Print(time.Since(s))
}