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

x/staking: cli migration to use gRPC query client #6728

Merged
merged 22 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a340052
migrated to use gRPC query client
atheeshp Jul 15, 2020
12940d3
removed codecs usage
atheeshp Jul 15, 2020
dd571a7
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Jul 15, 2020
aa6699c
review change
atheeshp Jul 15, 2020
3f15bd3
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Jul 16, 2020
cdd0a39
added read command flags
atheeshp Jul 16, 2020
8548f3d
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Jul 16, 2020
b660b0a
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Jul 16, 2020
2bfb3d5
Merge branch 'master' into atheesh/5921-grpc-cli-migration-staking
fedekunze Jul 16, 2020
2deb1fb
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Jul 16, 2020
316c55e
added pagination flags
atheeshp Jul 17, 2020
082d3a8
Merge branch 'atheesh/5921-grpc-cli-migration-staking' of github.com:…
atheeshp Jul 17, 2020
daefb37
fixed limit issue
atheeshp Jul 17, 2020
4f5e201
added helper function for default pagination flags
atheeshp Jul 17, 2020
c094491
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/59…
atheeshp Jul 17, 2020
88f2aae
Merge branch 'master' into atheesh/5921-grpc-cli-migration-staking
mergify[bot] Jul 17, 2020
c665872
review changes
atheeshp Jul 17, 2020
bf3273a
Merge branch 'atheesh/5921-grpc-cli-migration-staking' of github.com:…
atheeshp Jul 17, 2020
08d2548
review change
atheeshp Jul 17, 2020
956183d
review changes
atheeshp Jul 17, 2020
34b21d6
Merge branch 'master' into atheesh/5921-grpc-cli-migration-staking
mergify[bot] Jul 17, 2020
3c742e9
Merge branch 'master' into atheesh/5921-grpc-cli-migration-staking
mergify[bot] Jul 17, 2020
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
11 changes: 11 additions & 0 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const (
FlagPage = "page"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove this one?

Copy link
Contributor Author

@atheeshp atheeshp Jul 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be yes after all module migrations done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, agreed with @atheeshp: auth,ibc,evidence,gov etc are all using FlagPage, probably should wait for those modules to switch to using gRPC & query.PageRequest first, or else this PR will become too big.

FlagLimit = "limit"
FlagSignMode = "sign-mode"
FlagPageKey = "page-key"
FlagOffset = "offset"
FlagCountTotal = "count-total"
)

// LineBreak can be included in a command list to provide a blank line
Expand Down Expand Up @@ -123,6 +126,14 @@ func AddTxFlagsToCmd(cmd *cobra.Command) {
viper.BindPFlag(FlagKeyringBackend, cmd.Flags().Lookup(FlagKeyringBackend))
}

// AddPaginationFlagsToCmd adds common paginations flags to command
anilcse marked this conversation as resolved.
Show resolved Hide resolved
func AddPaginationFlagsToCmd(cmd *cobra.Command, query string) {
cmd.Flags().String(FlagPageKey, "", fmt.Sprintf("pagination page-key of %s to query for", query))
cmd.Flags().Uint64(FlagOffset, 0, fmt.Sprintf("pagination offset of %s to query for", query))
cmd.Flags().Uint64(FlagLimit, 100, fmt.Sprintf("pagination limit of %s to query for", query))
cmd.Flags().Bool(FlagCountTotal, false, fmt.Sprintf("count total number of records in %s to query for", query))
}

// GasSetting encapsulates the possible values passed through the --gas flag.
type GasSetting struct {
Simulate bool
Expand Down
21 changes: 21 additions & 0 deletions client/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package client

import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/spf13/pflag"
)

// Paginate returns the correct starting and ending index for a paginated query,
// given that client provides a desired page and limit of objects and the handler
// provides the total number of objects. The start page is assumed to be 1-indexed.
Expand Down Expand Up @@ -35,3 +41,18 @@ func Paginate(numObjs, page, limit, defLimit int) (start, end int) {

return start, end
}

// ReadPageRequest reads and builds the necessary page request flags for pagination.
func ReadPageRequest(flagSet *pflag.FlagSet) *query.PageRequest {
pageKey, _ := flagSet.GetString(flags.FlagPageKey)
offset, _ := flagSet.GetUint64(flags.FlagOffset)
limit, _ := flagSet.GetUint64(flags.FlagLimit)
countTotal, _ := flagSet.GetBool(flags.FlagCountTotal)

return &query.PageRequest{
Key: []byte(pageKey),
Offset: offset,
Limit: limit,
CountTotal: countTotal,
}
}
Loading