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

feat: Improve withdraw-all-rewards UX #9781

Merged
merged 8 commits into from
Jul 28, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Client Breaking Changes

* [\#9594](https://github.com/cosmos/cosmos-sdk/pull/9594) Remove legacy REST API. Please see the [REST Endpoints Migration guide](https://docs.cosmos.network/master/migrations/rest.html) to migrate to the new REST endpoints.
* [\#9781](https://github.com/cosmos/cosmos-sdk/pull/9781) Improve`withdraw-all-rewards` UX when broadcast mode `async` or `async` is used.


### CLI Breaking Changes
Expand Down
12 changes: 9 additions & 3 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
)

const (
MaxMessagesPerTxDefault = 5
MaxMessagesPerTxDefault = 0
)

// NewTxCmd returns a root CLI command handler for all x/distribution transaction commands.
Expand Down Expand Up @@ -126,11 +126,12 @@ func NewWithdrawAllRewardsCmd() *cobra.Command {
Short: "withdraw all delegations rewards for a delegator",
Long: strings.TrimSpace(
fmt.Sprintf(`Withdraw all rewards for a single delegator.
Note that if you use this command with --%[2]s=%[3]s or --%[2]s=%[4]s, the %[5]s flag will automatically be set to 0.

Example:
$ %s tx distribution withdraw-all-rewards --from mykey
$ %[1]s tx distribution withdraw-all-rewards --from mykey
`,
version.AppName,
version.AppName, flags.FlagBroadcastMode, flags.BroadcastSync, flags.BroadcastAsync, FlagMaxMessagesPerTx,
),
),
Args: cobra.NoArgs,
Expand Down Expand Up @@ -167,6 +168,11 @@ $ %s tx distribution withdraw-all-rewards --from mykey
}

chunkSize, _ := cmd.Flags().GetInt(FlagMaxMessagesPerTx)
if clientCtx.BroadcastMode != flags.BroadcastBlock && chunkSize > 0 {
return fmt.Errorf("cannot use broadcast mode %[1]s with %[2]s != 0",
clientCtx.BroadcastMode, FlagMaxMessagesPerTx)
}

return newSplitAndApply(tx.GenerateOrBroadcastTxCLI, clientCtx, cmd.Flags(), msgs, chunkSize)
},
}
Expand Down