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: reformat KeyOwnerAccount #833

Merged
merged 3 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 @@ -167,7 +167,7 @@ func (k Keeper) IsActiveChannel(ctx sdk.Context, connectionID, portID string) bo
// GetInterchainAccountAddress retrieves the InterchainAccount address from the store associated with the provided connectionID and portID
func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := icatypes.KeyOwnerAccount(connectionID, portID)
key := icatypes.KeyOwnerAccount(portID, connectionID)

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

acc := icatypes.RegisteredInterchainAccount{
ConnectionId: keySplit[1],
PortId: keySplit[2],
ConnectionId: keySplit[2],
PortId: keySplit[1],
AccountAddress: string(iterator.Value()),
}

Expand All @@ -200,5 +200,5 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredI
// SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated connectionID and portID
func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portID, address string) {
store := ctx.KVStore(k.storeKey)
store.Set(icatypes.KeyOwnerAccount(connectionID, portID), []byte(address))
store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address))
}
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 @@ -156,7 +156,7 @@ func (k Keeper) IsActiveChannel(ctx sdk.Context, connectionID, portID string) bo
// GetInterchainAccountAddress retrieves the InterchainAccount address from the store associated with the provided connectionID and portID
func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, connectionID, portID string) (string, bool) {
store := ctx.KVStore(k.storeKey)
key := icatypes.KeyOwnerAccount(connectionID, portID)
key := icatypes.KeyOwnerAccount(portID, connectionID)

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

acc := icatypes.RegisteredInterchainAccount{
ConnectionId: keySplit[1],
PortId: keySplit[2],
ConnectionId: keySplit[2],
PortId: keySplit[1],
AccountAddress: string(iterator.Value()),
}

Expand All @@ -189,5 +189,5 @@ func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredI
// SetInterchainAccountAddress stores the InterchainAccount address, keyed by the associated connectionID and portID
func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portID, address string) {
store := ctx.KVStore(k.storeKey)
store.Set(icatypes.KeyOwnerAccount(connectionID, portID), []byte(address))
store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address))
}
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 @@ -44,8 +44,8 @@ func KeyActiveChannel(portID, connectionID string) []byte {
}

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

// KeyPort creates and returns a new key used for port 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 @@ -10,6 +10,6 @@ func (suite *TypesTestSuite) TestKeyActiveChannel() {
}

func (suite *TypesTestSuite) TestKeyOwnerAccount() {
key := types.KeyOwnerAccount("connection-id", "port-id")
suite.Require().Equal("owner/connection-id/port-id", string(key))
key := types.KeyOwnerAccount("port-id", "connection-id")
suite.Require().Equal("owner/port-id/connection-id", string(key))
}