Newer
Older
import (
"context"
"fmt"
"strings"
"github.com/ethereum/go-ethereum/internal/cli/server/proto"
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
"github.com/golang/protobuf/ptypes/empty"
)
// StatusCommand is the command to output the status of the client
type StatusCommand struct {
*Meta2
}
// Help implements the cli.Command interface
func (p *StatusCommand) Help() string {
return `Usage: bor status
Output the status of the client`
}
// Synopsis implements the cli.Command interface
func (c *StatusCommand) Synopsis() string {
return "Output the status of the client"
}
// Run implements the cli.Command interface
func (c *StatusCommand) Run(args []string) int {
flags := c.NewFlagSet("status")
if err := flags.Parse(args); err != nil {
c.UI.Error(err.Error())
return 1
}
borClt, err := c.BorConn()
if err != nil {
c.UI.Error(err.Error())
return 1
}
status, err := borClt.Status(context.Background(), &empty.Empty{})
if err != nil {
c.UI.Error(err.Error())
return 1
}
c.UI.Output(printStatus(status))
return 0
}
func printStatus(status *proto.StatusResponse) string {
printHeader := func(h *proto.Header) string {
return formatKV([]string{
fmt.Sprintf("Hash|%s", h.Hash),
fmt.Sprintf("Number|%d", h.Number),
})
}
forks := make([]string, len(status.Forks)+1)
forks[0] = "Name|Block|Enabled"
for i, d := range status.Forks {
forks[i+1] = fmt.Sprintf("%s|%d|%v", d.Name, d.Block, !d.Disabled)
}
full := []string{
"General",
formatKV([]string{
fmt.Sprintf("Num peers|%d", status.NumPeers),
fmt.Sprintf("Sync mode|%s", status.SyncMode),
}),
"\nCurrent Header",
printHeader(status.CurrentHeader),
"\nCurrent Block",
printHeader(status.CurrentBlock),
"\nSyncing",
formatKV([]string{
fmt.Sprintf("Current block|%d", status.Syncing.CurrentBlock),
fmt.Sprintf("Highest block|%d", status.Syncing.HighestBlock),
fmt.Sprintf("Starting block|%d", status.Syncing.StartingBlock),
}),