forked from aergoio/aergo
/
current.go
60 lines (48 loc) · 1.1 KB
/
current.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
/*
* @file
* @copyright defined in aergo/LICENSE.txt
*/
package cmd
import (
"context"
"github.com/mr-tron/base58/base58"
"github.com/aergoio/aergo/cmd/aergocli/util"
"github.com/aergoio/aergo/types"
"github.com/spf13/cobra"
)
var CurrentPeersCmd = &cobra.Command{
Use: "current",
Short: "Get current peers list",
Run: execCurrentPeers,
}
var cpKey string
var cpSize int
func init() {
rootCmd.AddCommand(CurrentPeersCmd)
CurrentPeersCmd.Flags().StringVar(&cpKey, "ref", "", "Reference Key")
CurrentPeersCmd.Flags().IntVar(&cpSize, "size", 20, "Max list size")
}
func execCurrentPeers(cmd *cobra.Command, args []string) {
var blockHash []byte
var err error
if cmd.Flags().Changed("ref") == true {
blockHash, err = base58.Decode(cpKey)
if err != nil {
cmd.Printf("Failed: %s", err.Error())
return
}
}
if cpSize <= 0 {
cpSize = 20
}
uparams := &types.Paginations{
Ref: blockHash,
Size: uint32(cpSize),
}
msg, err := client.CurrentList(context.Background(), uparams)
if err != nil {
cmd.Printf("Failed: %s", err.Error())
return
}
cmd.Println(util.JSON(msg))
}