1
1
package cli
2
2
3
3
import (
4
- "context"
5
-
6
4
"github.com/cosmos/cosmos-sdk/client"
7
5
"github.com/cosmos/cosmos-sdk/client/flags"
8
6
"github.com/spf13/cobra"
@@ -21,33 +19,37 @@ func GetQueryCmd() *cobra.Command {
21
19
}
22
20
23
21
queryCmd .AddCommand (
24
- GetQueryCmdKey (),
25
22
GetQueryCmdKeys (),
23
+ GetQueryCmdKey (),
26
24
GetQueryCmdRewards (),
27
25
GetQueryCmdReward (),
28
- GetQueryCmdLocks (),
29
26
GetQueryCmdLock (),
27
+ GetQueryCmdLocks (),
30
28
)
31
29
32
30
return queryCmd
33
31
}
34
32
35
- // GetQueryCmdKey implements the key query command.
36
- func GetQueryCmdKey () * cobra.Command {
33
+ // GetQueryCmdKeys implements the keys query command.
34
+ func GetQueryCmdKeys () * cobra.Command {
37
35
cmd := & cobra.Command {
38
- Use : "key [name] " ,
39
- Short : "shows information of the key " ,
40
- Args : cobra .ExactArgs ( 1 ) ,
36
+ Use : "keys " ,
37
+ Short : "shows all keys " ,
38
+ Args : cobra .NoArgs ,
41
39
RunE : func (cmd * cobra.Command , args []string ) error {
42
- clientCtx := client .GetClientContextFromCmd (cmd )
40
+ clientCtx , err := client .GetClientQueryContext (cmd )
41
+ if err != nil {
42
+ return err
43
+ }
44
+
43
45
queryClient := types .NewQueryClient (clientCtx )
44
46
45
- res , err := queryClient . Key (
46
- context . Background (),
47
- & types. QueryKeyRequest {
48
- Key : args [ 0 ],
49
- },
50
- )
47
+ pageReq , err := client . ReadPageRequest ( cmd . Flags ())
48
+ if err != nil {
49
+ return err
50
+ }
51
+
52
+ res , err := queryClient . Keys ( cmd . Context (), & types. QueryKeysRequest { Pagination : pageReq } )
51
53
if err != nil {
52
54
return err
53
55
}
@@ -56,27 +58,32 @@ func GetQueryCmdKey() *cobra.Command {
56
58
},
57
59
}
58
60
61
+ flags .AddPaginationFlagsToCmd (cmd , "keys" )
59
62
flags .AddQueryFlagsToCmd (cmd )
60
63
61
64
return cmd
62
65
}
63
66
64
- // GetQueryCmdKeys implements the keys query command.
65
- func GetQueryCmdKeys () * cobra.Command {
67
+ // GetQueryCmdKey implements the key query command.
68
+ func GetQueryCmdKey () * cobra.Command {
66
69
cmd := & cobra.Command {
67
- Use : "keys " ,
68
- Short : "shows all keys " ,
69
- Args : cobra .NoArgs ,
70
+ Use : "key [name] " ,
71
+ Short : "shows information of the key " ,
72
+ Args : cobra .ExactArgs ( 1 ) ,
70
73
RunE : func (cmd * cobra.Command , args []string ) error {
71
- clientCtx := client .GetClientContextFromCmd (cmd )
72
- queryClient := types .NewQueryClient (clientCtx )
73
-
74
- pageReq , err := client .ReadPageRequest (cmd .Flags ())
74
+ clientCtx , err := client .GetClientQueryContext (cmd )
75
75
if err != nil {
76
76
return err
77
77
}
78
78
79
- res , err := queryClient .Keys (context .Background (), & types.QueryKeysRequest {Pagination : pageReq })
79
+ queryClient := types .NewQueryClient (clientCtx )
80
+
81
+ res , err := queryClient .Key (
82
+ cmd .Context (),
83
+ & types.QueryKeyRequest {
84
+ Key : args [0 ],
85
+ },
86
+ )
80
87
if err != nil {
81
88
return err
82
89
}
@@ -85,7 +92,6 @@ func GetQueryCmdKeys() *cobra.Command {
85
92
},
86
93
}
87
94
88
- flags .AddPaginationFlagsToCmd (cmd , "keys" )
89
95
flags .AddQueryFlagsToCmd (cmd )
90
96
91
97
return cmd
@@ -94,15 +100,25 @@ func GetQueryCmdKeys() *cobra.Command {
94
100
// GetQueryCmdRewards implements the rewards query command.
95
101
func GetQueryCmdRewards () * cobra.Command {
96
102
cmd := & cobra.Command {
97
- Use : "rewards [locker_address ]" ,
103
+ Use : "rewards [staker_address ]" ,
98
104
Short : "shows all rewards of an address" ,
99
105
Args : cobra .ExactArgs (1 ),
100
106
RunE : func (cmd * cobra.Command , args []string ) error {
101
- clientCtx := client .GetClientContextFromCmd (cmd )
107
+ clientCtx , err := client .GetClientQueryContext (cmd )
108
+ if err != nil {
109
+ return err
110
+ }
111
+
102
112
queryClient := types .NewQueryClient (clientCtx )
103
113
104
- res , err := queryClient .Rewards (context .Background (), & types.QueryRewardsRequest {
105
- LockerAddress : args [0 ],
114
+ pageReq , err := client .ReadPageRequest (cmd .Flags ())
115
+ if err != nil {
116
+ return err
117
+ }
118
+
119
+ res , err := queryClient .Rewards (cmd .Context (), & types.QueryRewardsRequest {
120
+ StakerAddress : args [0 ],
121
+ Pagination : pageReq ,
106
122
})
107
123
if err != nil {
108
124
return err
@@ -121,15 +137,19 @@ func GetQueryCmdRewards() *cobra.Command {
121
137
// GetQueryCmdReward implements the reward query command.
122
138
func GetQueryCmdReward () * cobra.Command {
123
139
cmd := & cobra.Command {
124
- Use : "reward [locker_address ] [key_name]" ,
125
- Short : "shows the reward of an locker address for the key" ,
140
+ Use : "reward [staker_address ] [key_name]" ,
141
+ Short : "shows the reward of an staker address for the key" ,
126
142
Args : cobra .ExactArgs (2 ),
127
143
RunE : func (cmd * cobra.Command , args []string ) error {
128
- clientCtx := client .GetClientContextFromCmd (cmd )
144
+ clientCtx , err := client .GetClientQueryContext (cmd )
145
+ if err != nil {
146
+ return err
147
+ }
148
+
129
149
queryClient := types .NewQueryClient (clientCtx )
130
150
131
- res , err := queryClient .Reward (context . Background (), & types.QueryRewardRequest {
132
- LockerAddress : args [0 ],
151
+ res , err := queryClient .Reward (cmd . Context (), & types.QueryRewardRequest {
152
+ StakerAddress : args [0 ],
133
153
Key : args [1 ],
134
154
})
135
155
if err != nil {
@@ -148,15 +168,25 @@ func GetQueryCmdReward() *cobra.Command {
148
168
// GetQueryCmdLocks implements the locks query command.
149
169
func GetQueryCmdLocks () * cobra.Command {
150
170
cmd := & cobra.Command {
151
- Use : "locks [locker_address ]" ,
152
- Short : "shows all locks of an locker address" ,
171
+ Use : "locks [staker_address ]" ,
172
+ Short : "shows all locks of an staker address" ,
153
173
Args : cobra .ExactArgs (1 ),
154
174
RunE : func (cmd * cobra.Command , args []string ) error {
155
- clientCtx := client .GetClientContextFromCmd (cmd )
175
+ clientCtx , err := client .GetClientQueryContext (cmd )
176
+ if err != nil {
177
+ return err
178
+ }
179
+
156
180
queryClient := types .NewQueryClient (clientCtx )
157
181
158
- res , err := queryClient .Locks (context .Background (), & types.QueryLocksRequest {
159
- LockerAddress : args [0 ],
182
+ pageReq , err := client .ReadPageRequest (cmd .Flags ())
183
+ if err != nil {
184
+ return err
185
+ }
186
+
187
+ res , err := queryClient .Locks (cmd .Context (), & types.QueryLocksRequest {
188
+ StakerAddress : args [0 ],
189
+ Pagination : pageReq ,
160
190
})
161
191
if err != nil {
162
192
return err
@@ -175,15 +205,19 @@ func GetQueryCmdLocks() *cobra.Command {
175
205
// GetQueryCmdLock implements the lock query command.
176
206
func GetQueryCmdLock () * cobra.Command {
177
207
cmd := & cobra.Command {
178
- Use : "lock [locker_address ] [key_name]" ,
179
- Short : "shows the lock of an locker address for the key" ,
208
+ Use : "lock [staker_address ] [key_name]" ,
209
+ Short : "shows the lock of an staker address for the key" ,
180
210
Args : cobra .ExactArgs (2 ),
181
211
RunE : func (cmd * cobra.Command , args []string ) error {
182
- clientCtx := client .GetClientContextFromCmd (cmd )
212
+ clientCtx , err := client .GetClientQueryContext (cmd )
213
+ if err != nil {
214
+ return err
215
+ }
216
+
183
217
queryClient := types .NewQueryClient (clientCtx )
184
218
185
- res , err := queryClient .Lock (context . Background (), & types.QueryLockRequest {
186
- LockerAddress : args [0 ],
219
+ res , err := queryClient .Lock (cmd . Context (), & types.QueryLockRequest {
220
+ StakerAddress : args [0 ],
187
221
Key : args [1 ],
188
222
})
189
223
if err != nil {
0 commit comments