-
Notifications
You must be signed in to change notification settings - Fork 113
/
query.go
110 lines (92 loc) · 2.91 KB
/
query.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package cli
import (
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/spf13/cobra"
"github.com/axelarnetwork/axelar-core/x/snapshot/keeper"
"github.com/axelarnetwork/axelar-core/x/snapshot/types"
)
// GetQueryCmd returns the cli query commands for this module
func GetQueryCmd(queryRoute string) *cobra.Command {
evmQueryCmd := &cobra.Command{
Use: "snapshot",
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
evmQueryCmd.AddCommand(
GetCmdGetProxy(queryRoute),
GetCmdGetOperator(queryRoute),
GetParams(),
)
return evmQueryCmd
}
// GetCmdGetProxy returns the proxy address associated to some operator address
func GetCmdGetProxy(queryRoute string) *cobra.Command {
cmd := &cobra.Command{
Use: "proxy [operator address]",
Short: "Fetch the proxy address associated with [operator address] and status (active/inactive)",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", queryRoute, keeper.QProxy, args[0]), nil)
if err != nil {
return sdkerrors.Wrapf(err, types.ErrFProxyAddress)
}
fmt.Println(string(res))
return nil
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetCmdGetOperator returns the operator address associated to some proxy address
func GetCmdGetOperator(queryRoute string) *cobra.Command {
cmd := &cobra.Command{
Use: "operator [proxy address]",
Short: "Fetch the operator address associated with [proxy address]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", queryRoute, keeper.QOperator, args[0]), nil)
if err != nil {
return sdkerrors.Wrapf(err, types.ErrFOperatorAddress)
}
fmt.Println(string(res))
return nil
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
// GetParams returns the snapshot params
func GetParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Returns the params for the snapshot module",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryServiceClient(clientCtx)
res, err := queryClient.Params(cmd.Context(), &types.ParamsRequest{})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}