diff --git a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go index 1bc75623f71..8084c8e5d66 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/handshake.go @@ -67,7 +67,7 @@ func (k Keeper) OnChanOpenInit( panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) } - if channel.State == channeltypes.OPEN { + if channel.IsOpen() { return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index eee552337d8..20d83a01ab8 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -146,7 +146,7 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID strin channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) - if found && channel.State == channeltypes.OPEN { + if found && channel.IsOpen() { return channelID, true } @@ -161,7 +161,7 @@ func (k Keeper) IsActiveChannelClosed(ctx sdk.Context, connectionID, portID stri } channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) - return found && channel.State == channeltypes.CLOSED + return found && channel.IsClosed() } // GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated connection and port identifiers diff --git a/modules/apps/27-interchain-accounts/host/keeper/handshake.go b/modules/apps/27-interchain-accounts/host/keeper/handshake.go index 8d43071ac2a..f565ad65a7d 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/handshake.go +++ b/modules/apps/27-interchain-accounts/host/keeper/handshake.go @@ -51,7 +51,7 @@ func (k Keeper) OnChanOpenTry( panic(fmt.Sprintf("active channel mapping set for %s but channel does not exist in channel store", activeChannelID)) } - if channel.State == channeltypes.OPEN { + if channel.IsOpen() { return "", errorsmod.Wrapf(icatypes.ErrActiveChannelAlreadySet, "existing active channel %s for portID %s is already OPEN", activeChannelID, portID) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 1de40965a2f..40698005c46 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -17,7 +17,6 @@ import ( genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" - channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" @@ -146,7 +145,7 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, connectionID, portID strin channel, found := k.channelKeeper.GetChannel(ctx, portID, channelID) - if found && channel.State == channeltypes.OPEN { + if found && channel.IsOpen() { return channelID, true } diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index 92241432503..61ab05407c1 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -385,7 +385,7 @@ func (k Keeper) ChanCloseInit( return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } - if channel.State == types.CLOSED { + if channel.IsClosed() { return errorsmod.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") } @@ -441,7 +441,7 @@ func (k Keeper) ChanCloseConfirm( return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID) } - if channel.State == types.CLOSED { + if channel.IsClosed() { return errorsmod.Wrap(types.ErrInvalidChannelState, "channel is already CLOSED") } diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index c0248917306..a596c3d7558 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -171,7 +171,7 @@ func (k Keeper) TimeoutExecuted( // emit an event marking that we have processed the timeout emitTimeoutPacketEvent(ctx, packet, channel) - if channel.Ordering == types.ORDERED && channel.State == types.CLOSED { + if channel.Ordering == types.ORDERED && channel.IsClosed() { emitChannelClosedEvent(ctx, packet, channel) } diff --git a/modules/core/04-channel/types/channel.go b/modules/core/04-channel/types/channel.go index 012b571fb07..1ba7b78c4f6 100644 --- a/modules/core/04-channel/types/channel.go +++ b/modules/core/04-channel/types/channel.go @@ -51,6 +51,16 @@ func (ch Channel) GetVersion() string { return ch.Version } +// IsOpen returns true if the channel state is OPEN +func (ch Channel) IsOpen() bool { + return ch.State == OPEN +} + +// IsClosed returns true if the channel state is CLOSED +func (ch Channel) IsClosed() bool { + return ch.State == CLOSED +} + // ValidateBasic performs a basic validation of the channel fields func (ch Channel) ValidateBasic() error { if ch.State == UNINITIALIZED {