github.com/Finschia/finschia-sdk@v0.48.1/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  	"github.com/Finschia/finschia-sdk/store/prefix"
    10  	sdk "github.com/Finschia/finschia-sdk/types"
    11  	"github.com/Finschia/finschia-sdk/types/query"
    12  	"github.com/Finschia/finschia-sdk/x/slashing/types"
    13  )
    14  
    15  var _ types.QueryServer = Keeper{}
    16  
    17  func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
    18  	if req == nil {
    19  		return nil, status.Errorf(codes.InvalidArgument, "empty request")
    20  	}
    21  
    22  	ctx := sdk.UnwrapSDKContext(c)
    23  	params := k.GetParams(ctx)
    24  
    25  	return &types.QueryParamsResponse{Params: params}, nil
    26  }
    27  
    28  func (k Keeper) SigningInfo(c context.Context, req *types.QuerySigningInfoRequest) (*types.QuerySigningInfoResponse, error) {
    29  	if req == nil {
    30  		return nil, status.Errorf(codes.InvalidArgument, "empty request")
    31  	}
    32  
    33  	if req.ConsAddress == "" {
    34  		return nil, status.Errorf(codes.InvalidArgument, "invalid request")
    35  	}
    36  
    37  	consAddr, err := sdk.ConsAddressFromBech32(req.ConsAddress)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	ctx := sdk.UnwrapSDKContext(c)
    43  	signingInfo, found := k.GetValidatorSigningInfo(ctx, consAddr)
    44  	if !found {
    45  		return nil, status.Errorf(codes.NotFound, "SigningInfo not found for validator %s", req.ConsAddress)
    46  	}
    47  
    48  	return &types.QuerySigningInfoResponse{ValSigningInfo: signingInfo}, nil
    49  }
    50  
    51  func (k Keeper) SigningInfos(c context.Context, req *types.QuerySigningInfosRequest) (*types.QuerySigningInfosResponse, error) {
    52  	if req == nil {
    53  		return nil, status.Errorf(codes.InvalidArgument, "empty request")
    54  	}
    55  
    56  	ctx := sdk.UnwrapSDKContext(c)
    57  	store := ctx.KVStore(k.storeKey)
    58  	var signInfos []types.ValidatorSigningInfo
    59  
    60  	sigInfoStore := prefix.NewStore(store, types.ValidatorSigningInfoKeyPrefix)
    61  	pageRes, err := query.Paginate(sigInfoStore, req.Pagination, func(key []byte, value []byte) error {
    62  		var info types.ValidatorSigningInfo
    63  		err := k.cdc.Unmarshal(value, &info)
    64  		if err != nil {
    65  			return err
    66  		}
    67  		signInfos = append(signInfos, info)
    68  		return nil
    69  	})
    70  	if err != nil {
    71  		return nil, err
    72  	}
    73  	return &types.QuerySigningInfosResponse{Info: signInfos, Pagination: pageRes}, nil
    74  }