Skip to content

Commit

Permalink
feat: query provider info
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaru Wang committed Jul 31, 2023
1 parent 8ddb410 commit 81f2952
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 46 deletions.
3 changes: 3 additions & 0 deletions proto/interchain_security/ccv/consumer/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ message QueryProviderInfoRequest {}

message QueryProviderInfoResponse {
string ChainID = 1;
string ClientID = 2;
string ConnectionID = 3;
string ChannelID = 4;
}
25 changes: 19 additions & 6 deletions x/ccv/consumer/keeper/provider_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,33 @@ 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) {
providerClientID, found := k.GetProviderClientID(ctx)
if !found {
return nil, nil
consumerChannelID, found := k.GetProviderChannel(ctx)
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
}
clientState, found := k.clientKeeper.GetClientState(ctx, providerClientID)

providerConnection := consumerConnection.GetCounterparty()

providerClientState, found := k.clientKeeper.GetClientState(ctx, providerConnection.GetClientID())
if !found {
// todo if return err?
return nil, nil
}
providerChainID := clientState.(*ibctm.ClientState).ChainId
providerChainID := providerClientState.(*ibctm.ClientState).ChainId

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

return &resp, nil
Expand Down
235 changes: 195 additions & 40 deletions x/ccv/consumer/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/ccv/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type PortKeeper interface {
// ConnectionKeeper defines the expected IBC connection keeper
type ConnectionKeeper interface {
GetConnection(ctx sdk.Context, connectionID string) (conntypes.ConnectionEnd, bool)
GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, ibcexported.ConnectionI, error)
}

// ClientKeeper defines the expected IBC client keeper
Expand Down

0 comments on commit 81f2952

Please sign in to comment.