Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add provider info query #1164

Merged
merged 21 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ service Query {
rpc QueryParams(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/interchain_security/ccv/consumer/params";
}

rpc QueryProviderChainInfo(QueryProviderInfoRequest) returns (QueryProviderInfoResponse) {
option (google.api.http).get = "/interchain_security/ccv/consumer/provider-info";
}
}

// NextFeeDistributionEstimate holds information about next fee distribution
Expand Down Expand Up @@ -52,3 +56,12 @@ message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

message QueryProviderInfoRequest {}
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved

message QueryProviderInfoResponse {
string ChainID = 1;
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
string ClientID = 2;
string ConnectionID = 3;
string ChannelID = 4;
}
12 changes: 11 additions & 1 deletion x/ccv/consumer/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"google.golang.org/grpc/status"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
)

Expand Down Expand Up @@ -40,3 +39,14 @@ func (k Keeper) QueryParams(c context.Context,

return &types.QueryParamsResponse{Params: p}, nil
}

func (k Keeper) QueryProviderChainInfo(c context.Context,
req *types.QueryProviderInfoRequest,
) (*types.QueryProviderInfoResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}

return k.GetProviderChainInfo(ctx)
}
37 changes: 37 additions & 0 deletions x/ccv/consumer/keeper/provider_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
)

func (k Keeper) GetProviderChainInfo(ctx sdk.Context) (*types.QueryProviderInfoResponse, error) {
consumerChannelID, found := k.GetProviderChannel(ctx)
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
consumerChannel, _ := k.channelKeeper.GetChannel(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
providerChannelID := consumerChannel.GetCounterparty().GetChannelID()

_, consumerConnection, err := k.connectionKeeper.GetChannelConnection(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
if err != nil {
return nil, err
}

providerConnection := consumerConnection.GetCounterparty()

providerClientState, found := k.clientKeeper.GetClientState(ctx, providerConnection.GetClientID())
if !found {
// todo if return err?
yaruwangway marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil
}
providerChainID := providerClientState.(*ibctm.ClientState).ChainId

resp := types.QueryProviderInfoResponse{
ChainID: providerChainID,
ClientID: providerConnection.GetClientID(),
ConnectionID: providerConnection.GetConnectionID(),
ChannelID: providerChannelID,
}

return &resp, nil
}
Loading
Loading