Skip to content

Commit

Permalink
Merge PR cosmos#4494: Fix validator-outstanding-rewards command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Jun 6, 2019
1 parent 5f9c3fd commit 1ccf0c2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .pending/bugfixes/sdk/4493-Fix-validator-o
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#4493 Fix validator-outstanding-rewards command. It now takes as an argument
a validator address.
36 changes: 31 additions & 5 deletions x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,46 @@ func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
// GetCmdQueryValidatorOutstandingRewards implements the query validator outstanding rewards command.
func GetCmdQueryValidatorOutstandingRewards(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "validator-outstanding-rewards",
Args: cobra.NoArgs,
Use: "validator-outstanding-rewards [validator]",
Args: cobra.ExactArgs(1),
Short: "Query distribution outstanding (un-withdrawn) rewards for a validator and all their delegations",
Long: strings.TrimSpace(
fmt.Sprintf(`Query distribution outstanding (un-withdrawn) rewards
for a validator and all their delegations.
Example:
$ %s query distr validator-outstanding-rewards cosmosvaloper1lwjmdnks33xwnmfayc64ycprww49n33mtm92ne
`,
version.ClientName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

route := fmt.Sprintf("custom/%s/validator_outstanding_rewards", queryRoute)
res, err := cliCtx.QueryWithData(route, []byte{})
valAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
return err
}

params := types.NewQueryValidatorOutstandingRewardsParams(valAddr)
bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
}

resp, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryValidatorOutstandingRewards),
bz,
)
if err != nil {
return err
}

var outstandingRewards types.ValidatorOutstandingRewards
cdc.MustUnmarshalJSON(res, &outstandingRewards)
if err := cdc.UnmarshalJSON(resp, &outstandingRewards); err != nil {
return err
}

return cliCtx.PrintOutput(outstandingRewards)
},
}
Expand Down

0 comments on commit 1ccf0c2

Please sign in to comment.