forked from eoscanada/eosc
/
voteStatus.go
68 lines (58 loc) · 1.62 KB
/
voteStatus.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
package cmd
import (
"context"
"fmt"
eos "github.com/sebastianmontero/eos-go"
"github.com/spf13/cobra"
)
var voteStatusCmd = &cobra.Command{
Use: "status [voter name]",
Short: "Display the current vote status for a given account.",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
api := getAPI()
voterName := toAccount(args[0], "voter name")
response, err := api.GetTableRows(
context.Background(),
eos.GetTableRowsRequest{
Code: "eosio",
Scope: "eosio",
Table: "voters",
JSON: true,
LowerBound: string(voterName),
Limit: 1,
},
)
errorCheck("get table row", err)
var voterInfos []eos.VoterInfo
err = response.JSONToStructs(&voterInfos)
errorCheck("reading voter_info", err)
found := false
for _, info := range voterInfos {
if info.Owner == voterName {
found = true
fmt.Println("Voter: ", info.Owner)
if info.IsProxy != 0 {
fmt.Println("Registered as a proxy voter: true")
fmt.Println("Proxied vote weight: ", info.ProxiedVoteWeight)
} else {
fmt.Println("Registered as a proxy voter: false")
}
if info.Proxy != "" {
fmt.Println("Voting via proxy: ", info.Proxy)
fmt.Println("Last vote weight: ", info.LastVoteWeight)
} else {
fmt.Println("Producers list: ", info.Producers)
fmt.Println("Staked amount: ", info.Staked)
fmt.Printf("Last vote weight: %f\n", info.LastVoteWeight)
}
}
}
if !found {
errorCheck("vote status", fmt.Errorf("unable to find vote status for %s", voterName))
}
},
}
func init() {
voteCmd.AddCommand(voteStatusCmd)
}