-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_query.go
49 lines (38 loc) · 1.33 KB
/
grpc_query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package keeper
import (
"context"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/ingenuity-build/quicksilver/x/interchainquery/types"
)
var _ types.QuerySrvrServer = Keeper{}
// Queries returns information about registered zones.
func (k Keeper) Queries(c context.Context, req *types.QueryRequestsRequest) (*types.QueryRequestsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
var queries []types.Query
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixQuery)
pageRes, err := query.FilteredPaginate(store, req.Pagination, func(_, value []byte, accumulate bool) (bool, error) {
var query types.Query
if err := k.cdc.Unmarshal(value, &query); err != nil {
return false, err
}
if query.ChainId == req.ChainId && (query.LastEmission.IsNil() || query.LastEmission.IsZero() || query.LastEmission.GTE(query.LastHeight)) {
queries = append(queries, query)
return true, nil
}
return false, nil
})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &types.QueryRequestsResponse{
Queries: queries,
Pagination: pageRes,
}, nil
}