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: update Paginate to use FilterPaginate in ClientStates and ConnectionChannels grpc queries #3010

Merged
merged 21 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 6 additions & 5 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,26 @@ func (q Keeper) ClientStates(c context.Context, req *types.QueryClientStatesRequ
clientStates := types.IdentifiedClientStates{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), host.KeyClientStorePrefix)

pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) {
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
// filter any metadata stored under client state key
keySplit := strings.Split(string(key), "/")
if keySplit[len(keySplit)-1] != "clientState" {
return nil
return false, nil
}

clientState, err := q.UnmarshalClientState(value)
if err != nil {
return err
return false, err
}

clientID := keySplit[1]
if err := host.ClientIdentifierValidator(clientID); err != nil {
return err
return false, err
}

identifiedClient := types.NewIdentifiedClientState(clientID, clientState)
clientStates = append(clientStates, identifiedClient)
return nil
return true, nil
})
if err != nil {
return nil, err
Expand Down
11 changes: 6 additions & 5 deletions modules/core/04-channel/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,27 @@ func (q Keeper) ConnectionChannels(c context.Context, req *types.QueryConnection
channels := []*types.IdentifiedChannel{}
store := prefix.NewStore(ctx.KVStore(q.storeKey), []byte(host.KeyChannelEndPrefix))

pageRes, err := query.Paginate(store, req.Pagination, func(key, value []byte) error {
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(key, value []byte, accumulate bool) (bool, error) {
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
// filter any metadata stored under channel key
var result types.Channel
if err := q.cdc.Unmarshal(value, &result); err != nil {
return err
return false, err
}

// ignore channel and continue to the next item if the connection is
// different than the requested one
if result.ConnectionHops[0] != req.Connection {
return nil
return false, nil
}

portID, channelID, err := host.ParseChannelPath(string(key))
if err != nil {
return err
return false, err
}

identifiedChannel := types.NewIdentifiedChannel(portID, channelID, result)
channels = append(channels, &identifiedChannel)
return nil
return true, nil
})
if err != nil {
return nil, err
Expand Down