Skip to content

Commit

Permalink
fix: add wrapper struct for light client modules DI
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Apr 27, 2024
1 parent b8b156b commit 5a72470
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions modules/core/02-client/types/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ func (rtr *Router) GetRoute(clientID string) (exported.LightClientModule, bool)
}
return rtr.routes[clientType], true
}

type LightClientModuleWrapper struct{ exported.LightClientModule }

func NewLightClientModuleWrapper(clientModule exported.LightClientModule) LightClientModuleWrapper {
return LightClientModuleWrapper{
clientModule,
}
}

func (LightClientModuleWrapper) IsOnePerModuleType() {}
4 changes: 2 additions & 2 deletions modules/core/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func InvokeAddAppRoutes(keeper *ibckeeper.Keeper, appRoutes []porttypes.IBCModul
// InvokeAddClientRoutes defines a depinject Invoker for registering ibc light client modules on the core ibc client router.
// TODO: Maybe this should align with app router. i.e. create router here, add routes, and set on ibc keeper.
// For app_v1 this would be the same approach, just create clientRouter in app.go instead of implicit creation inside of ibc.NewKeeper()
func InvokeAddClientRoutes(keeper *ibckeeper.Keeper, clientRoutes map[string]exported.LightClientModule) {
func InvokeAddClientRoutes(keeper *ibckeeper.Keeper, clientRoutes map[string]clienttypes.LightClientModuleWrapper) {
router := keeper.ClientKeeper.GetRouter()
for modName, route := range clientRoutes {
router.AddRoute(modName, route)
router.AddRoute(modName, route.LightClientModule)
}
}
8 changes: 5 additions & 3 deletions modules/light-clients/06-solomachine/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"

modulev1 "github.com/cosmos/ibc-go/api/ibc/lightclients/solomachine/module/v1"

Check failure on line 10 in modules/light-clients/06-solomachine/depinject.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

Check failure on line 10 in modules/light-clients/06-solomachine/depinject.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
)

var (
Expand Down Expand Up @@ -38,13 +40,13 @@ type ModuleInputs struct {
type ModuleOutputs struct {
depinject.Out

LightClientModule *LightClientModule
Module appmodule.AppModule
LightClientModuleWrapper clienttypes.LightClientModuleWrapper
Module appmodule.AppModule
}

// ProvideModule returns the 06-solomachine module outputs for dependency injection
func ProvideModule(in ModuleInputs) ModuleOutputs {
lightClientModule := NewLightClientModule(in.Cdc)
m := NewAppModule(lightClientModule)
return ModuleOutputs{LightClientModule: &lightClientModule, Module: m}
return ModuleOutputs{LightClientModuleWrapper: clienttypes.NewLightClientModuleWrapper(&lightClientModule), Module: m}
}
8 changes: 5 additions & 3 deletions modules/light-clients/07-tendermint/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

modulev1 "github.com/cosmos/ibc-go/api/ibc/lightclients/tendermint/module/v1"

Check failure on line 12 in modules/light-clients/07-tendermint/depinject.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)

Check failure on line 12 in modules/light-clients/07-tendermint/depinject.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/ibc-go) --custom-order (gci)
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
)

var (
Expand Down Expand Up @@ -41,8 +43,8 @@ type ModuleInputs struct {
type ModuleOutputs struct {
depinject.Out

LightClientModule *LightClientModule
Module appmodule.AppModule
LightClientModuleWrapper clienttypes.LightClientModuleWrapper
Module appmodule.AppModule
}

// ProvideModule returns the 07-tendermint module outputs for dependency injection
Expand All @@ -55,5 +57,5 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {

lightClientModule := NewLightClientModule(in.Cdc, authority.String())
m := NewAppModule(lightClientModule)
return ModuleOutputs{LightClientModule: &lightClientModule, Module: m}
return ModuleOutputs{LightClientModuleWrapper: clienttypes.NewLightClientModuleWrapper(&lightClientModule), Module: m}
}

0 comments on commit 5a72470

Please sign in to comment.