Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validator-outstanding-rewards command #4494

Merged
merged 3 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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