github.com/cosmos/cosmos-sdk@v0.50.10/x/slashing/keeper/grpc_query.go (about) 1 package keeper 2 3 import ( 4 "context" 5 6 "google.golang.org/grpc/codes" 7 "google.golang.org/grpc/status" 8 9 "cosmossdk.io/store/prefix" 10 11 "github.com/cosmos/cosmos-sdk/runtime" 12 "github.com/cosmos/cosmos-sdk/types/query" 13 "github.com/cosmos/cosmos-sdk/x/slashing/types" 14 ) 15 16 var _ types.QueryServer = Querier{} 17 18 type Querier struct { 19 Keeper 20 } 21 22 func NewQuerier(keeper Keeper) Querier { 23 return Querier{Keeper: keeper} 24 } 25 26 // Params returns parameters of x/slashing module 27 func (k Keeper) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { 28 if req == nil { 29 return nil, status.Errorf(codes.InvalidArgument, "empty request") 30 } 31 32 params, err := k.GetParams(ctx) 33 34 return &types.QueryParamsResponse{Params: params}, err 35 } 36 37 // SigningInfo returns signing-info of a specific validator. 38 func (k Keeper) SigningInfo(ctx context.Context, req *types.QuerySigningInfoRequest) (*types.QuerySigningInfoResponse, error) { 39 if req == nil { 40 return nil, status.Errorf(codes.InvalidArgument, "empty request") 41 } 42 43 if req.ConsAddress == "" { 44 return nil, status.Errorf(codes.InvalidArgument, "invalid request") 45 } 46 47 consAddr, err := k.sk.ConsensusAddressCodec().StringToBytes(req.ConsAddress) 48 if err != nil { 49 return nil, err 50 } 51 52 signingInfo, err := k.GetValidatorSigningInfo(ctx, consAddr) 53 if err != nil { 54 return nil, status.Errorf(codes.NotFound, "SigningInfo not found for validator %s", req.ConsAddress) 55 } 56 57 return &types.QuerySigningInfoResponse{ValSigningInfo: signingInfo}, nil 58 } 59 60 // SigningInfos returns signing-infos of all validators. 61 func (k Keeper) SigningInfos(ctx context.Context, req *types.QuerySigningInfosRequest) (*types.QuerySigningInfosResponse, error) { 62 if req == nil { 63 return nil, status.Errorf(codes.InvalidArgument, "empty request") 64 } 65 66 store := k.storeService.OpenKVStore(ctx) 67 var signInfos []types.ValidatorSigningInfo 68 69 sigInfoStore := prefix.NewStore(runtime.KVStoreAdapter(store), types.ValidatorSigningInfoKeyPrefix) 70 pageRes, err := query.Paginate(sigInfoStore, req.Pagination, func(key, value []byte) error { 71 var info types.ValidatorSigningInfo 72 err := k.cdc.Unmarshal(value, &info) 73 if err != nil { 74 return err 75 } 76 signInfos = append(signInfos, info) 77 return nil 78 }) 79 if err != nil { 80 return nil, err 81 } 82 return &types.QuerySigningInfosResponse{Info: signInfos, Pagination: pageRes}, nil 83 }