Skip to content

Commit

Permalink
feat: query all provider info
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaru Wang committed Aug 1, 2023
1 parent 81f2952 commit aeba225
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 10 additions & 0 deletions testutil/keeper/mocks.go

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

18 changes: 13 additions & 5 deletions x/ccv/consumer/keeper/provider_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,31 @@ import (
)

func (k Keeper) GetProviderChainInfo(ctx sdk.Context) (*types.QueryProviderInfoResponse, error) {
// get the channelID for the channel to the provider.
consumerChannelID, found := k.GetProviderChannel(ctx)
consumerChannel, _ := k.channelKeeper.GetChannel(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
providerChannelID := consumerChannel.GetCounterparty().GetChannelID()
if !found {
return nil, nil
}
consumerChannel, found := k.channelKeeper.GetChannel(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
if !found {
return nil, nil
}

_, consumerConnection, err := k.connectionKeeper.GetChannelConnection(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
// from channel get connection
_, consumerConnection, err := k.channelKeeper.GetChannelConnection(ctx, ccvtypes.ConsumerPortID, consumerChannelID)
if err != nil {
return nil, err
}

providerChannelID := consumerChannel.GetCounterparty().GetChannelID()
providerConnection := consumerConnection.GetCounterparty()

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

resp := types.QueryProviderInfoResponse{
ChainID: providerChainID,
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type ChannelKeeper interface {
) (sequence uint64, err error)
WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error
ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error
GetChannelConnection(ctx sdk.Context, portID, channelID string) (string, ibcexported.ConnectionI, error)
}

// PortKeeper defines the expected IBC port keeper
Expand All @@ -92,7 +93,6 @@ 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 aeba225

Please sign in to comment.