Skip to content

Commit

Permalink
feat: integrate interchain account module
Browse files Browse the repository at this point in the history
  • Loading branch information
dadamu committed Feb 3, 2023
1 parent f4a96fe commit d355c48
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: other
pull_request: 1082
description: integrate interchain account module
backward_compatible: true
date: 2023-02-03T09:48:02.6497929Z
76 changes: 67 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ import (
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"

ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types"

"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"

Expand Down Expand Up @@ -248,6 +257,7 @@ var (
ibc.AppModuleBasic{},
ibctransfer.AppModuleBasic{},
ibcfee.AppModuleBasic{},
ica.AppModuleBasic{},

// Custom modules
profiles.AppModuleBasic{},
Expand All @@ -271,6 +281,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
wasm.ModuleName: {authtypes.Burner},
ibcfeetypes.ModuleName: nil,
icatypes.ModuleName: nil,
}
)

Expand Down Expand Up @@ -310,15 +321,19 @@ type DesmosApp struct {
WasmKeeper wasm.Keeper

// IBC modules
TransferKeeper ibctransferkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCFeeKeeper ibcfeekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCFeeKeeper ibcfeekeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedIBCTransferKeeper capabilitykeeper.ScopedKeeper
ScopedProfilesKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedIBCTransferKeeper capabilitykeeper.ScopedKeeper
ScopedProfilesKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper

// Custom modules
FeesKeeper feeskeeper.Keeper
Expand Down Expand Up @@ -376,6 +391,7 @@ func NewDesmosApp(

// IBC modules
ibcfeetypes.StoreKey, ibchost.StoreKey, ibctransfertypes.StoreKey,
icacontrollertypes.StoreKey, icahosttypes.StoreKey,

// Custom modules
profilestypes.StoreKey, relationshipstypes.StoreKey, subspacestypes.StoreKey,
Expand Down Expand Up @@ -408,6 +424,8 @@ func NewDesmosApp(
scopedIBCTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedProfilesKeeper := app.CapabilityKeeper.ScopeToModule(profilestypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)

// seal capability keeper after scoping modules
app.CapabilityKeeper.Seal()
Expand Down Expand Up @@ -481,6 +499,28 @@ func NewDesmosApp(
scopedIBCTransferKeeper,
)

// Create interchain account keepers
app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec,
keys[icahosttypes.StoreKey],
app.GetSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
)
app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec,
keys[icacontrollertypes.StoreKey],
app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper,
app.MsgServiceRouter(),
)

// Create fees keeper
app.FeesKeeper = feeskeeper.NewKeeper(app.appCodec, app.GetSubspace(feestypes.ModuleName))

Expand Down Expand Up @@ -626,11 +666,21 @@ func NewDesmosApp(
profilesIBCModule := ibcfee.NewIBCMiddleware(profiles.NewIBCModule(app.appCodec, app.ProfileKeeper), app.IBCFeeKeeper)
wasmIBCModule := ibcfee.NewIBCMiddleware(wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper), app.IBCFeeKeeper)

// Create static IBC router, add routes, then set and seal it
// TODO: After available ICA auth module released, replace nil the module
icaControllerIBCModule := ibcfee.NewIBCMiddleware(
icacontroller.NewIBCMiddleware(nil, app.ICAControllerKeeper),
app.IBCFeeKeeper)

icaHostIBCModule := ibcfee.NewIBCMiddleware(icahost.NewIBCModule(app.ICAHostKeeper), app.IBCFeeKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(profilestypes.ModuleName, profilesIBCModule).
AddRoute(wasm.ModuleName, wasmIBCModule)
AddRoute(wasm.ModuleName, wasmIBCModule).
AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)

app.IBCKeeper.SetRouter(ibcRouter)

/**** Module Options ****/
Expand Down Expand Up @@ -667,6 +717,7 @@ func NewDesmosApp(
ibc.NewAppModule(app.IBCKeeper),
ibctransfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),

// Custom modules
fees.NewAppModule(app.appCodec, app.FeesKeeper),
Expand Down Expand Up @@ -708,6 +759,7 @@ func NewDesmosApp(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,

// Custom modules
feestypes.ModuleName,
Expand Down Expand Up @@ -743,6 +795,7 @@ func NewDesmosApp(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,

// Custom modules
feestypes.ModuleName,
Expand Down Expand Up @@ -786,6 +839,7 @@ func NewDesmosApp(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
ibcfeetypes.ModuleName,
icatypes.ModuleName,

// Custom modules
feestypes.ModuleName,
Expand Down Expand Up @@ -935,6 +989,8 @@ func NewDesmosApp(
app.ScopedIBCTransferKeeper = scopedIBCTransferKeeper
app.ScopedProfilesKeeper = scopedProfilesKeeper
app.ScopedWasmKeeper = scopedWasmKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -1165,6 +1221,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino

paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)

paramsKeeper.Subspace(feestypes.ModuleName)
paramsKeeper.Subspace(subspacestypes.ModuleName)
Expand Down

0 comments on commit d355c48

Please sign in to comment.