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

chore: update portkey to include port ID #467

Merged
merged 8 commits into from
Oct 11, 2021
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState

// ExportGenesis exports transfer module's portID into its geneis state
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
portID := keeper.GetPort(ctx)
portID := keeper.GetPort(ctx, types.PortID)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved

return &types.GenesisState{
PortId: portID,
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/27-interchain-accounts/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}

// GetPort returns the portID for the interchain accounts module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context) string {
func (k Keeper) GetPort(ctx sdk.Context, portID string) string {
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
store := ctx.KVStore(k.storeKey)
return string(store.Get([]byte(types.PortKey)))
return string(store.Get(types.KeyPort(portID)))
}

// BindPort stores the provided portID and binds to it, returning the associated capability
func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability {
store := ctx.KVStore(k.storeKey)
store.Set([]byte(types.PortKey), []byte(portID))
store.Set(types.KeyPort(portID), []byte(portID))
damiannolan marked this conversation as resolved.
Show resolved Hide resolved

return k.portKeeper.BindPort(ctx, portID)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (suite *KeeperTestSuite) TestIsBound() {
}

func (suite *KeeperTestSuite) TestGetPort() {
port := suite.chainA.GetSimApp().ICAKeeper.GetPort(suite.chainA.GetContext())
port := suite.chainA.GetSimApp().ICAKeeper.GetPort(suite.chainA.GetContext(), types.PortID)
suite.Require().Equal(types.PortID, port)
}

Expand Down
21 changes: 16 additions & 5 deletions modules/apps/27-interchain-accounts/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ const (
)

var (
// PortKey defines the key to store the port ID in store
PortKey = []byte{0x01}
// ActiveChannelKeyPrefix defines the key prefix used to store active channels
ActiveChannelKeyPrefix = "activeChannel"

// OwnerKeyPrefix defines the key prefix used to store interchain accounts
OwnerKeyPrefix = "owner"

// PortKeyPrefix defines the key prefix used to store ports
PortKeyPrefix = "port"
)

// NewVersion returns a complete version string in the format: VersionPrefix + Delimter + AccAddress
Expand All @@ -39,10 +45,15 @@ func NewAppVersion(versionPrefix, accAddr string) string {

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

// KeyOwnerAccount creates and returns a new key used for owner account store operations
// KeyOwnerAccount creates and returns a new key used for interchain account store operations
func KeyOwnerAccount(portID string) []byte {
return []byte(fmt.Sprintf("owner/%s", portID))
return []byte(fmt.Sprintf("%s/%s", OwnerKeyPrefix, portID))
}

// KeyPort creates and returns a new key used for port store operations
func KeyPort(portID string) []byte {
return []byte(fmt.Sprintf("%s/%s", PortKeyPrefix, portID))
}