-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
76 lines (72 loc) · 2.02 KB
/
auth.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
package cmd
import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/spf13/cobra"
)
func authAccountCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "account [address]",
Aliases: []string{"acc"},
Short: "query an account for its number and sequence or pass no arguement to query default account",
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
cl := a.GetDefaultClient()
keyNameOrAddress := ""
if len(args) == 0 {
keyNameOrAddress = cl.Config.Key
} else {
keyNameOrAddress = args[0]
}
address, err := cl.AccountFromKeyOrAddress(keyNameOrAddress)
if err != nil {
return err
}
req := &authtypes.QueryAccountRequest{Address: cl.MustEncodeAccAddr(address)}
res, err := authtypes.NewQueryClient(cl).Account(cmd.Context(), req)
if err != nil {
return err
}
return cl.PrintObject(res)
},
}
return cmd
}
func authAccountsCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "accounts",
Aliases: []string{"accs"},
Short: "query all accounts on a given chain w/ pagination",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cl := a.GetDefaultClient()
pr, err := ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
req := &authtypes.QueryAccountsRequest{Pagination: pr}
res, err := authtypes.NewQueryClient(cl).Accounts(cmd.Context(), req)
if err != nil {
return err
}
return cl.PrintObject(res)
},
}
return paginationFlags(cmd, a.Viper)
}
func authParamsCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "parameters",
Aliases: []string{"param", "params", "p"},
Short: "query the current auth parameters",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
cl := a.GetDefaultClient()
res, err := authtypes.NewQueryClient(cl).Params(cmd.Context(), &authtypes.QueryParamsRequest{})
if err != nil {
return err
}
return cl.PrintObject(res)
},
}
return cmd
}