forked from blockpane/pvtop
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
51 lines (42 loc) · 1.04 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
package main
import (
"fmt"
"github.com/blockpane/pvtop/prevotes"
"log"
"os"
"time"
)
const refreshRate = time.Second
func main() {
log.SetFlags(log.Lshortfile | log.LstdFlags)
if len(os.Args) < 2 {
log.Fatal("please provide an rpc endpoint as the only argument")
}
networkName, err := prevotes.GetNetworkName(os.Args[1])
if err != nil {
log.Fatal(err)
}
fmt.Println("Please wait, getting validator information....")
v := prevotes.GetValNames(os.Args[1])
if v == nil {
log.Fatal("no validators found")
}
voteChan := make(chan []prevotes.VoteState)
pctChan := make(chan float64)
SummaryChan := make(chan string)
go prevotes.DrawScreen(networkName, voteChan, pctChan, SummaryChan)
tick := time.NewTicker(refreshRate)
for range tick.C {
votes, pct, hrs, dur, e := prevotes.GetPreVotes(os.Args[1], v)
if e != nil {
SummaryChan <- e.Error()
continue
}
if dur < 0 {
dur = 0
}
SummaryChan <- fmt.Sprintf("height/round/step: %s - pct: %.0f%% (%v)\n", hrs, pct*100, dur)
voteChan <- votes
pctChan <- pct
}
}