diff --git a/x/wasm/internal/keeper/query_plugins.go b/x/wasm/internal/keeper/query_plugins.go index fa61ab77b5..64f314a2ad 100644 --- a/x/wasm/internal/keeper/query_plugins.go +++ b/x/wasm/internal/keeper/query_plugins.go @@ -173,15 +173,24 @@ func IBCQuerier(wasm *Keeper, channelKeeper types.ChannelKeeper) func(ctx sdk.Co } return json.Marshal(res) } + // I just discovered we cannot query by port (how odd since they store it like this) + // Anyway, I will allow Port as an optional filter + // TODO: let's revisit this query (if needed, if we should change it) if request.ListChannels != nil { portID := request.ListChannels.PortID - if portID == "" { - contractInfo := wasm.GetContractInfo(ctx, caller) - portID = contractInfo.IBCPortID - } - // TODO: query the channels for this port + var channels wasmvmtypes.IBCEndpoints + channelKeeper.IterateChannels(ctx, func(ch types.IdentifiedChannel) bool { + if portID == "" || portID == ch.PortId { + newChan := wasmvmtypes.IBCEndpoint{ + PortID: ch.PortId, + ChannelID: ch.ChannelId, + } + channels = append(channels, newChan) + } + return false + }) res := wasmvmtypes.ListChannelsResponse{ - Channels: wasmvmtypes.IBCEndpoints{}, + Channels: channels, } return json.Marshal(res) } diff --git a/x/wasm/internal/keeper/wasmtesting/mock_keepers.go b/x/wasm/internal/keeper/wasmtesting/mock_keepers.go index d382a321cd..acee3a4082 100644 --- a/x/wasm/internal/keeper/wasmtesting/mock_keepers.go +++ b/x/wasm/internal/keeper/wasmtesting/mock_keepers.go @@ -12,6 +12,7 @@ type MockChannelKeeper struct { GetNextSequenceSendFn func(ctx sdk.Context, portID, channelID string) (uint64, bool) SendPacketFn func(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error ChanCloseInitFn func(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error + GetAllChannelsFn func(ctx sdk.Context) []channeltypes.IdentifiedChannel } func (m *MockChannelKeeper) GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) { @@ -21,6 +22,24 @@ func (m *MockChannelKeeper) GetChannel(ctx sdk.Context, srcPort, srcChan string) return m.GetChannelFn(ctx, srcPort, srcChan) } +func (m *MockChannelKeeper) GetAllChannels(ctx sdk.Context) []channeltypes.IdentifiedChannel { + if m.GetAllChannelsFn == nil { + panic("not supposed to be called!") + } + return m.GetAllChannelsFn(ctx) +} + +// Auto-implemented from GetAllChannels data +func (m *MockChannelKeeper) IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) { + channels := m.GetAllChannels(ctx) + for _, channel := range channels { + stop := cb(channel) + if stop { + break + } + } +} + func (m *MockChannelKeeper) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) { if m.GetNextSequenceSendFn == nil { panic("not supposed to be called!") diff --git a/x/wasm/internal/types/ibc.go b/x/wasm/internal/types/ibc.go index b042254bdb..e4f9d664aa 100644 --- a/x/wasm/internal/types/ibc.go +++ b/x/wasm/internal/types/ibc.go @@ -16,8 +16,12 @@ type ChannelKeeper interface { GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error + GetAllChannels(ctx sdk.Context) (channels []channeltypes.IdentifiedChannel) + IterateChannels(ctx sdk.Context, cb func(channeltypes.IdentifiedChannel) bool) } +type IdentifiedChannel = channeltypes.IdentifiedChannel + // ClientKeeper defines the expected IBC client keeper type ClientKeeper interface { GetClientConsensusState(ctx sdk.Context, clientID string) (connection ibcexported.ConsensusState, found bool)