-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
grpc_query.go
74 lines (59 loc) · 2.1 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package keeper
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)
var _ types.QueryServer = Keeper{}
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
params := k.GetParams(ctx)
return &types.QueryParamsResponse{Params: params}, nil
}
func (k Keeper) SigningInfo(c context.Context, req *types.QuerySigningInfoRequest) (*types.QuerySigningInfoResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
if req.ConsAddress == "" {
return nil, status.Errorf(codes.InvalidArgument, "invalid request")
}
consAddr, err := sdk.ConsAddressFromBech32(req.ConsAddress)
if err != nil {
return nil, err
}
ctx := sdk.UnwrapSDKContext(c)
signingInfo, found := k.GetValidatorSigningInfo(ctx, consAddr)
if !found {
return nil, status.Errorf(codes.NotFound, "SigningInfo not found for validator %s", req.ConsAddress)
}
return &types.QuerySigningInfoResponse{ValSigningInfo: signingInfo}, nil
}
func (k Keeper) SigningInfos(c context.Context, req *types.QuerySigningInfosRequest) (*types.QuerySigningInfosResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
store := ctx.KVStore(k.storeKey)
var signInfos []types.ValidatorSigningInfo
sigInfoStore := prefix.NewStore(store, types.ValidatorSigningInfoKeyPrefix)
pageRes, err := query.Paginate(sigInfoStore, req.Pagination, func(key []byte, value []byte) error {
var info types.ValidatorSigningInfo
err := k.cdc.Unmarshal(value, &info)
if err != nil {
return err
}
signInfos = append(signInfos, info)
return nil
})
if err != nil {
return nil, err
}
return &types.QuerySigningInfosResponse{Info: signInfos, Pagination: pageRes}, nil
}