From 798fb1247c0552b942e0e533d25159d129798f18 Mon Sep 17 00:00:00 2001 From: Sean King Date: Wed, 2 Feb 2022 16:25:13 +0100 Subject: [PATCH] refactor: reformat KeyOwnerAccount (#833) ## Description Reformats KeyOwnerAccount store key closes: [Damians Comment](https://github.com/cosmos/ibc-go/pull/823#pullrequestreview-870409614) --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [ ] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing) - [ ] Updated relevant documentation (`docs/`) or specification (`x//spec/`) - [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [ ] Re-reviewed `Files changed` in the Github PR explorer - [ ] Review `Codecov Report` in the comment section below once CI passes (cherry picked from commit bbcc09c3dfa828f123191ade39d373b432483d6b) --- .../27-interchain-accounts/controller/keeper/keeper.go | 8 ++++---- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 8 ++++---- modules/apps/27-interchain-accounts/types/keys.go | 4 ++-- modules/apps/27-interchain-accounts/types/keys_test.go | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go index 7216ccb7fa8..87af9ae9c6f 100644 --- a/modules/apps/27-interchain-accounts/controller/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/controller/keeper/keeper.go @@ -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 @@ -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()), } @@ -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)) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 181153a0fb5..ea3f8205c87 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -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 @@ -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()), } @@ -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)) } diff --git a/modules/apps/27-interchain-accounts/types/keys.go b/modules/apps/27-interchain-accounts/types/keys.go index c2bde682551..2bf05ffda3f 100644 --- a/modules/apps/27-interchain-accounts/types/keys.go +++ b/modules/apps/27-interchain-accounts/types/keys.go @@ -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 diff --git a/modules/apps/27-interchain-accounts/types/keys_test.go b/modules/apps/27-interchain-accounts/types/keys_test.go index 02da485bf32..94c7a3bed0d 100644 --- a/modules/apps/27-interchain-accounts/types/keys_test.go +++ b/modules/apps/27-interchain-accounts/types/keys_test.go @@ -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)) }