-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_query.go
executable file
·83 lines (65 loc) · 2.32 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
75
76
77
78
79
80
81
82
83
package keeper
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"cosmossdk.io/store/prefix"
"github.com/axiome-pro/axm-node/x/slashing/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/types/query"
)
var _ types.QueryServer = Querier{}
type Querier struct {
Keeper
}
func NewQuerier(keeper Keeper) Querier {
return Querier{Keeper: keeper}
}
// Params returns parameters of x/slashing module
func (k Keeper) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
params, err := k.GetParams(ctx)
return &types.QueryParamsResponse{Params: params}, err
}
// SigningInfo returns signing-info of a specific validator.
func (k Keeper) SigningInfo(ctx 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 := k.sk.ConsensusAddressCodec().StringToBytes(req.ConsAddress)
if err != nil {
return nil, err
}
signingInfo, err := k.GetValidatorSigningInfo(ctx, consAddr)
if err != nil {
return nil, status.Errorf(codes.NotFound, "SigningInfo not found for validator %s", req.ConsAddress)
}
return &types.QuerySigningInfoResponse{ValSigningInfo: signingInfo}, nil
}
// SigningInfos returns signing-infos of all validators.
func (k Keeper) SigningInfos(ctx context.Context, req *types.QuerySigningInfosRequest) (*types.QuerySigningInfosResponse, error) {
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
store := k.storeService.OpenKVStore(ctx)
var signInfos []types.ValidatorSigningInfo
sigInfoStore := prefix.NewStore(runtime.KVStoreAdapter(store), types.ValidatorSigningInfoKeyPrefix)
pageRes, err := query.Paginate(sigInfoStore, req.Pagination, func(key, 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
}