Skip to content

Commit

Permalink
refactor: ica depinject configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Apr 30, 2024
1 parent 1a232c0 commit 54bc954
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions modules/apps/27-interchain-accounts/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import (

modulev1 "github.com/cosmos/ibc-go/api/ibc/applications/interchain_accounts/module/v1"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
controllerKeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
hostKeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
controllerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host"
hostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
hosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
)
Expand All @@ -34,16 +38,17 @@ func init() {
type ModuleInputs struct {
depinject.In

// TODO: Config should define `controller_enabled` and `host_enabled` vars for keeper/module setup
Config *modulev1.Module
Cdc codec.Codec
ControllerKey *storetypes.KVStoreKey
HostKey *storetypes.KVStoreKey

Ics4Wrapper porttypes.ICS4Wrapper
ChannelKeeper types.ChannelKeeper
PortKeeper types.PortKeeper
ScopedKeeper capabilitykeeper.ScopedKeeper
AccountKeeper types.AccountKeeper
Ics4Wrapper porttypes.ICS4Wrapper
ChannelKeeper types.ChannelKeeper
PortKeeper types.PortKeeper
CapabilityKeeper capabilitykeeper.Keeper
AccountKeeper types.AccountKeeper

MsgRouter types.MessageRouter
QueryRouter types.QueryRouter
Expand All @@ -56,9 +61,10 @@ type ModuleInputs struct {
type ModuleOutputs struct {
depinject.Out

ControllerKeeper *controllerKeeper.Keeper
HostKeeper *hostKeeper.Keeper
ControllerKeeper *controllerkeeper.Keeper
HostKeeper *hostkeeper.Keeper
Module appmodule.AppModule
IBCModuleRoutes []porttypes.IBCModuleRoute
}

// ProvideModule returns the 27-interchain-accounts outputs for dependency injection
Expand All @@ -69,31 +75,49 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

controllerkeeper := controllerKeeper.NewKeeper(
scopedControllerKeeper := in.CapabilityKeeper.ScopeToModule(controllertypes.SubModuleName)
controllerKeeper := controllerkeeper.NewKeeper(
in.Cdc,
in.ControllerKey,
in.LegacySubspace,
in.Ics4Wrapper,
in.ChannelKeeper,
in.PortKeeper,
in.ScopedKeeper,
scopedControllerKeeper,
in.MsgRouter,
authority.String(),
)
hostkeeper := hostKeeper.NewKeeper(

scopedHostKeeper := in.CapabilityKeeper.ScopeToModule(hosttypes.SubModuleName)
hostKeeper := hostkeeper.NewKeeper(
in.Cdc,
in.HostKey,
in.LegacySubspace,
in.Ics4Wrapper,
in.ChannelKeeper,
in.PortKeeper,
in.AccountKeeper,
in.ScopedKeeper,
scopedHostKeeper,
in.MsgRouter,
in.QueryRouter,
authority.String(),
)
m := NewAppModule(&controllerkeeper, &hostkeeper)

return ModuleOutputs{ControllerKeeper: &controllerkeeper, HostKeeper: &hostkeeper, Module: m}
m := NewAppModule(&controllerKeeper, &hostKeeper)

controllerModule := controller.NewIBCMiddleware(nil, controllerKeeper)
hostModule := host.NewIBCModule(hostKeeper)

return ModuleOutputs{
ControllerKeeper: &controllerKeeper,
HostKeeper: &hostKeeper,
Module: m,
IBCModuleRoutes: []porttypes.IBCModuleRoute{
{
Name: controllertypes.SubModuleName, IBCModule: controllerModule,
},
{
Name: hosttypes.SubModuleName, IBCModule: hostModule,
},
},
}
}

0 comments on commit 54bc954

Please sign in to comment.