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

refactor: active channel key format #823

Merged
merged 5 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability
// GetActiveChannelID retrieves the active channelID from the store, keyed by the provided connectionID and portID
func (k Keeper) GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := icatypes.KeyActiveChannel(connectionID, portID)
key := icatypes.KeyActiveChannel(portID, connectionID)

if !store.Has(key) {
return "", false
Expand Down Expand Up @@ -141,8 +141,8 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel {
keySplit := strings.Split(string(iterator.Key()), "/")

ch := icatypes.ActiveChannel{
ConnectionId: keySplit[1],
PortId: keySplit[2],
ConnectionId: keySplit[2],
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
}

Expand All @@ -155,7 +155,7 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel {
// SetActiveChannelID stores the active channelID, keyed by the provided connectionID and portID
func (k Keeper) SetActiveChannelID(ctx sdk.Context, connectionID, portID, channelID string) {
store := ctx.KVStore(k.storeKey)
store.Set(icatypes.KeyActiveChannel(connectionID, portID), []byte(channelID))
store.Set(icatypes.KeyActiveChannel(portID, connectionID), []byte(channelID))
}

// IsActiveChannel returns true if there exists an active channel for the provided connectionID and portID, otherwise false
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability
// GetActiveChannelID retrieves the active channelID from the store keyed by the provided connectionID and portID
func (k Keeper) GetActiveChannelID(ctx sdk.Context, connectionID, portID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := icatypes.KeyActiveChannel(connectionID, portID)
key := icatypes.KeyActiveChannel(portID, connectionID)

if !store.Has(key) {
return "", false
Expand Down Expand Up @@ -130,8 +130,8 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel {
keySplit := strings.Split(string(iterator.Key()), "/")

ch := icatypes.ActiveChannel{
ConnectionId: keySplit[1],
PortId: keySplit[2],
ConnectionId: keySplit[2],
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
}

Expand All @@ -144,7 +144,7 @@ func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel {
// SetActiveChannelID stores the active channelID, keyed by the provided connectionID and portID
func (k Keeper) SetActiveChannelID(ctx sdk.Context, connectionID, portID, channelID string) {
store := ctx.KVStore(k.storeKey)
store.Set(icatypes.KeyActiveChannel(connectionID, portID), []byte(channelID))
store.Set(icatypes.KeyActiveChannel(portID, connectionID), []byte(channelID))
}

// IsActiveChannel returns true if there exists an active channel for the provided connectionID and portID, otherwise false
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var (
)

// KeyActiveChannel creates and returns a new key used for active channels store operations
func KeyActiveChannel(connectionID, portID string) []byte {
return []byte(fmt.Sprintf("%s/%s/%s", ActiveChannelKeyPrefix, connectionID, portID))
func KeyActiveChannel(portID, connectionID string) []byte {
return []byte(fmt.Sprintf("%s/%s/%s", ActiveChannelKeyPrefix, portID, connectionID))
}

// KeyOwnerAccount creates and returns a new key used for interchain account store operations
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/27-interchain-accounts/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

func (suite *TypesTestSuite) TestKeyActiveChannel() {
key := types.KeyActiveChannel("connection-id", "port-id")
suite.Require().Equal("activeChannel/connection-id/port-id", string(key))
key := types.KeyActiveChannel("port-id", "connection-id")
suite.Require().Equal("activeChannel/port-id/connection-id", string(key))
}

func (suite *TypesTestSuite) TestKeyOwnerAccount() {
Expand Down