Skip to content

Commit

Permalink
refactor: reformat KeyOwnerAccount (cosmos#833)
Browse files Browse the repository at this point in the history
## Description

Reformats KeyOwnerAccount store key 

closes: [Damians Comment](cosmos#823 (review)) 

---

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/<module>/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
  • Loading branch information
seantking authored Feb 2, 2022
1 parent fed6a86 commit bbcc09c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
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))
}

0 comments on commit bbcc09c

Please sign in to comment.