Skip to content

Commit

Permalink
Impl grpc query handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Nov 1, 2022
1 parent 6c7b6a0 commit a05c6ab
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper
import (
"context"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/interchain-security/x/ccv/provider/types"
Expand Down Expand Up @@ -79,8 +81,55 @@ func (k Keeper) QueryConsumerChainValidatorKeyMapping(goCtx context.Context, req

ctx := sdk.UnwrapSDKContext(goCtx)

// TODO:
_ = ctx
if _, found := k.GetConsumerClientId(ctx, req.ChainId); !found {
return nil, types.ErrNoConsumerChainFound
}

providerValidatorAddr, err := sdk.ValAddressFromBech32(req.ProviderValidatorAddress)
if err != nil {
return nil, err
}

validator, found := k.stakingKeeper.GetValidator(ctx, providerValidatorAddr)
if !found {
return nil, types.ErrNoValidatorFound
}

providerTMPublicKey, err := validator.TmConsPublicKey()
if err != nil {
return nil, sdkerrors.Wrapf(
types.ErrInvalidValidatorPubKey,
"cryptocodec error: %w",
err,
)
}

consumerTMPublicKey, found := k.KeyMap(ctx, req.ChainId).GetCurrentConsumerPubKeyFromProviderPubKey(providerTMPublicKey)

if !found {
return nil, types.ErrNoAssignedConsumerKeyFoundForValidator
}

consumerSDKPublicKey, err := cryptocodec.FromTmProtoPublicKey(consumerTMPublicKey)

if err != nil {
return nil, sdkerrors.Wrapf(
// TODO: is this the right kind of error?
types.ErrInvalidValidatorPubKey,
"cryptocodec error: %w",
err,
)
}

var pubKeyAny *codectypes.Any
if consumerSDKPublicKey != nil {
var err error
if pubKeyAny, err = codectypes.NewAnyWithValue(consumerSDKPublicKey); err != nil {
return nil, err
}
}

return &types.QueryConsumerChainValidatorKeyMappingResponse{}, nil
return &types.QueryConsumerChainValidatorKeyMappingResponse{
ConsumerValidatorPubkey: pubKeyAny,
}, nil
}

0 comments on commit a05c6ab

Please sign in to comment.