2020-07-06 14:54:25 -07:00
|
|
|
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 == nil {
|
|
|
|
return nil, status.Errorf(codes.InvalidArgument, "invalid request")
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := sdk.UnwrapSDKContext(c)
|
|
|
|
signingInfo, found := k.GetValidatorSigningInfo(ctx, req.ConsAddress)
|
|
|
|
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)
|
2020-07-20 09:51:16 -07:00
|
|
|
pageRes, err := query.Paginate(sigInfoStore, req.Pagination, func(key []byte, value []byte) error {
|
2020-07-06 14:54:25 -07:00
|
|
|
var info types.ValidatorSigningInfo
|
|
|
|
err := k.cdc.UnmarshalBinaryBare(value, &info)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
signInfos = append(signInfos, info)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-20 09:51:16 -07:00
|
|
|
return &types.QuerySigningInfosResponse{Info: signInfos, Pagination: pageRes}, nil
|
2020-07-06 14:54:25 -07:00
|
|
|
}
|