Skip to content

Commit

Permalink
imp: adding IsOpen and IsClosed methods to Channel type (#4152) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AbolfazlSoltaani authored Jul 21, 2023
1 parent 31b3c60 commit ec93b64
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions modules/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 10 additions & 0 deletions modules/core/04-channel/types/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ec93b64

Please sign in to comment.