@@ -73,12 +73,26 @@ func delegatorRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) htt
73
73
return
74
74
}
75
75
76
- // query for rewards from a particular delegator
77
- res , ok := checkResponseQueryDelegatorTotalRewards (w , cliCtx , queryRoute , mux .Vars (r )["delegatorAddr" ])
76
+ delegatorAddr , ok := checkDelegatorAddressVar (w , r )
78
77
if ! ok {
79
78
return
80
79
}
81
80
81
+ params := types .NewQueryDelegatorParams (delegatorAddr )
82
+ bz , err := cliCtx .Codec .MarshalJSON (params )
83
+ if err != nil {
84
+ rest .WriteErrorResponse (w , http .StatusBadRequest , fmt .Sprintf ("failed to marshal params: %s" , err ))
85
+ return
86
+ }
87
+
88
+ route := fmt .Sprintf ("custom/%s/%s" , queryRoute , types .QueryDelegatorTotalRewards )
89
+ res , height , err := cliCtx .QueryWithData (route , bz )
90
+ if err != nil {
91
+ rest .WriteErrorResponse (w , http .StatusInternalServerError , err .Error ())
92
+ return
93
+ }
94
+
95
+ cliCtx = cliCtx .WithHeight (height )
82
96
rest .PostProcessResponse (w , cliCtx , res )
83
97
}
84
98
}
@@ -91,12 +105,16 @@ func delegationRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) ht
91
105
return
92
106
}
93
107
108
+ delAddr := mux .Vars (r )["delegatorAddr" ]
109
+ valAddr := mux .Vars (r )["validatorAddr" ]
110
+
94
111
// query for rewards from a particular delegation
95
- res , ok := checkResponseQueryDelegationRewards (w , cliCtx , queryRoute , mux . Vars ( r )[ "delegatorAddr" ], mux . Vars ( r )[ "validatorAddr" ] )
112
+ res , height , ok := checkResponseQueryDelegationRewards (w , cliCtx , queryRoute , delAddr , valAddr )
96
113
if ! ok {
97
114
return
98
115
}
99
116
117
+ cliCtx = cliCtx .WithHeight (height )
100
118
rest .PostProcessResponse (w , cliCtx , res )
101
119
}
102
120
}
@@ -147,8 +165,7 @@ func NewValidatorDistInfo(operatorAddr sdk.AccAddress, rewards sdk.DecCoins,
147
165
// HTTP request handler to query validator's distribution information
148
166
func validatorInfoHandlerFn (cliCtx context.CLIContext , queryRoute string ) http.HandlerFunc {
149
167
return func (w http.ResponseWriter , r * http.Request ) {
150
- valAddr := mux .Vars (r )["validatorAddr" ]
151
- validatorAddr , ok := checkValidatorAddressVar (w , r )
168
+ valAddr , ok := checkValidatorAddressVar (w , r )
152
169
if ! ok {
153
170
return
154
171
}
@@ -159,28 +176,39 @@ func validatorInfoHandlerFn(cliCtx context.CLIContext, queryRoute string) http.H
159
176
}
160
177
161
178
// query commission
162
- commissionRes , err := common .QueryValidatorCommission (cliCtx , queryRoute , validatorAddr )
179
+ bz , err := common .QueryValidatorCommission (cliCtx , queryRoute , valAddr )
163
180
if err != nil {
164
181
rest .WriteErrorResponse (w , http .StatusInternalServerError , err .Error ())
165
182
return
166
183
}
167
184
168
- var valCom types.ValidatorAccumulatedCommission
169
- cliCtx .Codec .MustUnmarshalJSON (commissionRes , & valCom )
185
+ var commission types.ValidatorAccumulatedCommission
186
+ if err := cliCtx .Codec .UnmarshalJSON (bz , & commission ); err != nil {
187
+ rest .WriteErrorResponse (w , http .StatusInternalServerError , err .Error ())
188
+ return
189
+ }
170
190
171
191
// self bond rewards
172
- delAddr := sdk .AccAddress (validatorAddr )
173
- rewardsRes , ok := checkResponseQueryDelegationRewards (w , cliCtx , queryRoute , delAddr .String (), valAddr )
192
+ delAddr := sdk .AccAddress (valAddr )
193
+ bz , height , ok := checkResponseQueryDelegationRewards (w , cliCtx , queryRoute , delAddr .String (), valAddr . String () )
174
194
if ! ok {
175
195
return
176
196
}
177
197
178
198
var rewards sdk.DecCoins
179
- cliCtx .Codec .MustUnmarshalJSON (rewardsRes , & rewards )
199
+ if err := cliCtx .Codec .UnmarshalJSON (bz , & rewards ); err != nil {
200
+ rest .WriteErrorResponse (w , http .StatusInternalServerError , err .Error ())
201
+ return
202
+ }
180
203
181
- // Prepare response
182
- res := cliCtx .Codec .MustMarshalJSON (NewValidatorDistInfo (delAddr , rewards , valCom ))
183
- rest .PostProcessResponse (w , cliCtx , res )
204
+ bz , err = cliCtx .Codec .MarshalJSON (NewValidatorDistInfo (delAddr , rewards , commission ))
205
+ if err != nil {
206
+ rest .WriteErrorResponse (w , http .StatusInternalServerError , err .Error ())
207
+ return
208
+ }
209
+
210
+ cliCtx = cliCtx .WithHeight (height )
211
+ rest .PostProcessResponse (w , cliCtx , bz )
184
212
}
185
213
}
186
214
@@ -199,12 +227,13 @@ func validatorRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) htt
199
227
}
200
228
201
229
delAddr := sdk .AccAddress (validatorAddr ).String ()
202
- res , ok := checkResponseQueryDelegationRewards (w , cliCtx , queryRoute , delAddr , valAddr )
230
+ bz , height , ok := checkResponseQueryDelegationRewards (w , cliCtx , queryRoute , delAddr , valAddr )
203
231
if ! ok {
204
232
return
205
233
}
206
234
207
- rest .PostProcessResponse (w , cliCtx , res )
235
+ cliCtx = cliCtx .WithHeight (height )
236
+ rest .PostProcessResponse (w , cliCtx , bz )
208
237
}
209
238
}
210
239
@@ -277,28 +306,15 @@ func outstandingRewardsHandlerFn(cliCtx context.CLIContext, queryRoute string) h
277
306
}
278
307
}
279
308
280
- func checkResponseQueryDelegatorTotalRewards (
281
- w http.ResponseWriter , cliCtx context.CLIContext , queryRoute , delAddr string ,
282
- ) (res []byte , ok bool ) {
283
-
284
- res , err := common .QueryDelegatorTotalRewards (cliCtx , queryRoute , delAddr )
285
- if err != nil {
286
- rest .WriteErrorResponse (w , http .StatusInternalServerError , err .Error ())
287
- return nil , false
288
- }
289
-
290
- return res , true
291
- }
292
-
293
309
func checkResponseQueryDelegationRewards (
294
310
w http.ResponseWriter , cliCtx context.CLIContext , queryRoute , delAddr , valAddr string ,
295
- ) (res []byte , ok bool ) {
311
+ ) (res []byte , height int64 , ok bool ) {
296
312
297
- res , err := common .QueryDelegationRewards (cliCtx , queryRoute , delAddr , valAddr )
313
+ res , height , err := common .QueryDelegationRewards (cliCtx , queryRoute , delAddr , valAddr )
298
314
if err != nil {
299
315
rest .WriteErrorResponse (w , http .StatusInternalServerError , err .Error ())
300
- return nil , false
316
+ return nil , 0 , false
301
317
}
302
318
303
- return res , true
319
+ return res , height , true
304
320
}
0 commit comments