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: restructure controller/host genesis types #799

Closed
wants to merge 3 commits into from
Closed
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
76 changes: 2 additions & 74 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
- [InterchainAccount](#ibc.applications.interchain_accounts.v1.InterchainAccount)

- [ibc/applications/interchain_accounts/v1/genesis.proto](#ibc/applications/interchain_accounts/v1/genesis.proto)
- [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel)
- [ControllerGenesisState](#ibc.applications.interchain_accounts.v1.ControllerGenesisState)
- [GenesisState](#ibc.applications.interchain_accounts.v1.GenesisState)
- [HostGenesisState](#ibc.applications.interchain_accounts.v1.HostGenesisState)
- [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount)

- [ibc/applications/interchain_accounts/v1/metadata.proto](#ibc/applications/interchain_accounts/v1/metadata.proto)
- [Metadata](#ibc.applications.interchain_accounts.v1.Metadata)
Expand Down Expand Up @@ -308,40 +304,6 @@ An InterchainAccount is defined as a BaseAccount & the address of the account ow



<a name="ibc.applications.interchain_accounts.v1.ActiveChannel"></a>

### ActiveChannel
ActiveChannel contains a pairing of port ID and channel ID for an active interchain accounts channel


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `port_id` | [string](#string) | | |
| `channel_id` | [string](#string) | | |






<a name="ibc.applications.interchain_accounts.v1.ControllerGenesisState"></a>

### ControllerGenesisState
ControllerGenesisState defines the interchain accounts controller genesis state


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `active_channels` | [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel) | repeated | |
| `interchain_accounts` | [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount) | repeated | |
| `ports` | [string](#string) | repeated | |
| `params` | [ibc.applications.interchain_accounts.controller.v1.Params](#ibc.applications.interchain_accounts.controller.v1.Params) | | |






<a name="ibc.applications.interchain_accounts.v1.GenesisState"></a>

### GenesisState
Expand All @@ -350,42 +312,8 @@ GenesisState defines the interchain accounts genesis state

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `controller_genesis_state` | [ControllerGenesisState](#ibc.applications.interchain_accounts.v1.ControllerGenesisState) | | |
| `host_genesis_state` | [HostGenesisState](#ibc.applications.interchain_accounts.v1.HostGenesisState) | | |






<a name="ibc.applications.interchain_accounts.v1.HostGenesisState"></a>

### HostGenesisState
HostGenesisState defines the interchain accounts host genesis state


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `active_channels` | [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel) | repeated | |
| `interchain_accounts` | [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount) | repeated | |
| `port` | [string](#string) | | |
| `params` | [ibc.applications.interchain_accounts.host.v1.Params](#ibc.applications.interchain_accounts.host.v1.Params) | | |






<a name="ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount"></a>

### RegisteredInterchainAccount
RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `port_id` | [string](#string) | | |
| `account_address` | [string](#string) | | |
| `controller_genesis_state` | [ibc.applications.interchain_accounts.controller.v1.ControllerGenesisState](#ibc.applications.interchain_accounts.controller.v1.ControllerGenesisState) | | |
| `host_genesis_state` | [ibc.applications.interchain_accounts.host.v1.HostGenesisState](#ibc.applications.interchain_accounts.host.v1.HostGenesisState) | | |



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
)

// InitGenesis initializes the interchain accounts controller application state from a provided genesis state
func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.ControllerGenesisState) {
func InitGenesis(ctx sdk.Context, keeper Keeper, state types.ControllerGenesisState) {
for _, portID := range state.Ports {
if !keeper.IsBound(ctx, portID) {
cap := keeper.BindPort(ctx, portID)
Expand All @@ -32,7 +33,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state icatypes.ControllerGenesi
}

// ExportGenesis returns the interchain accounts controller exported genesis
func ExportGenesis(ctx sdk.Context, keeper Keeper) icatypes.ControllerGenesisState {
func ExportGenesis(ctx sdk.Context, keeper Keeper) types.ControllerGenesisState {
return icatypes.NewControllerGenesisState(
keeper.GetAllActiveChannels(ctx),
keeper.GetAllInterchainAccounts(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ package keeper_test
import (
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
)

func (suite *KeeperTestSuite) TestInitGenesis() {
suite.SetupTest()

genesisState := icatypes.ControllerGenesisState{
ActiveChannels: []icatypes.ActiveChannel{
genesisState := types.ControllerGenesisState{
ActiveChannels: []types.ActiveChannel{
{
PortId: TestPortID,
ChannelId: ibctesting.FirstChannelID,
},
},
InterchainAccounts: []icatypes.RegisteredInterchainAccount{
InterchainAccounts: []types.RegisteredInterchainAccount{
{
PortId: TestPortID,
AccountAddress: TestAccAddress.String(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,16 @@ func (k Keeper) GetOpenActiveChannel(ctx sdk.Context, portID string) (string, bo
}

// GetAllActiveChannels returns a list of all active interchain accounts controller channels and their associated port identifiers
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []icatypes.ActiveChannel {
func (k Keeper) GetAllActiveChannels(ctx sdk.Context) []types.ActiveChannel {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.ActiveChannelKeyPrefix))
defer iterator.Close()

var activeChannels []icatypes.ActiveChannel
var activeChannels []types.ActiveChannel
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

ch := icatypes.ActiveChannel{
ch := types.ActiveChannel{
PortId: keySplit[1],
ChannelId: string(iterator.Value()),
}
Expand Down Expand Up @@ -176,15 +176,15 @@ func (k Keeper) GetInterchainAccountAddress(ctx sdk.Context, portID string) (str
}

// GetAllInterchainAccounts returns a list of all registered interchain account addresses and their associated controller port identifiers
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []icatypes.RegisteredInterchainAccount {
func (k Keeper) GetAllInterchainAccounts(ctx sdk.Context) []types.RegisteredInterchainAccount {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(icatypes.OwnerKeyPrefix))

var interchainAccounts []icatypes.RegisteredInterchainAccount
var interchainAccounts []types.RegisteredInterchainAccount
for ; iterator.Valid(); iterator.Next() {
keySplit := strings.Split(string(iterator.Key()), "/")

acc := icatypes.RegisteredInterchainAccount{
acc := types.RegisteredInterchainAccount{
PortId: keySplit[1],
AccountAddress: string(iterator.Value()),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
Expand Down Expand Up @@ -179,7 +180,7 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), expectedPortID, expectedChannelID)

expectedChannels := []icatypes.ActiveChannel{
expectedChannels := []types.ActiveChannel{
{
PortId: TestPortID,
ChannelId: path.EndpointA.ChannelID,
Expand Down Expand Up @@ -211,7 +212,7 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {

suite.chainA.GetSimApp().ICAControllerKeeper.SetInterchainAccountAddress(suite.chainA.GetContext(), expectedPortID, expectedAccAddr)

expectedAccounts := []icatypes.RegisteredInterchainAccount{
expectedAccounts := []types.RegisteredInterchainAccount{
{
PortId: TestPortID,
AccountAddress: TestAccAddress.String(),
Expand Down
Loading