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

feat(wip): add depinject support for app v2 #3868

Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module github.com/cosmos/ibc-go/v7

require (
cosmossdk.io/api v0.3.1
cosmossdk.io/core v0.5.1
cosmossdk.io/depinject v1.0.0-alpha.3
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.1
github.com/armon/go-metrics v0.4.1
Expand Down Expand Up @@ -33,8 +35,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.29.0 // indirect
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
cosmossdk.io/log v1.1.0 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
Expand Down
67 changes: 67 additions & 0 deletions modules/core/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ import (
"encoding/json"
"fmt"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

Expand All @@ -24,6 +31,7 @@ import (
"github.com/cosmos/ibc-go/v7/modules/core/client/cli"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/ibc-go/v7/modules/core/keeper"
modulev1 "github.com/cosmos/ibc-go/v7/modules/core/module/v1"
"github.com/cosmos/ibc-go/v7/modules/core/simulation"
"github.com/cosmos/ibc-go/v7/modules/core/types"
)
Expand Down Expand Up @@ -98,6 +106,14 @@ type AppModule struct {
keeper *keeper.Keeper
}

var _ appmodule.AppModule = AppModule{}

// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}

// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}

// NewAppModule creates a new AppModule object
func NewAppModule(k *keeper.Keeper) AppModule {
return AppModule{
Expand Down Expand Up @@ -197,3 +213,54 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {
func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return nil
}

// App Wiring Setup

func init() {
appmodule.Register(&modulev1.Module{},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to Register complains with:

cannot use &modulev1.Module{} (value of type *"github.com/cosmos/ibc-go/v7/modules/core/module/v1".Module) as protoreflect.ProtoMessage value in argument to appmodule.Register: *"github.com/cosmos/ibc-go/v7/modules/core/module/v1".Module does not implement protoreflect.ProtoMessage (missing method ProtoReflect)compiler[InvalidIfaceAssign](https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#InvalidIfaceAssign)

But I don't know why it doesn't implement protoreflect.ProtoMessage...

appmodule.Provide(ProvideModule),
)
}

type ModuleInputs struct {
depinject.In

Config *modulev1.Module
Cdc codec.Codec
Key *store.KVStoreKey

StakingKeeper clienttypes.StakingKeeper
UpgradeKeeper clienttypes.UpgradeKeeper
ScopedKeeper capabilitykeeper.ScopedKeeper

// LegacySubspace is used solely for migration of x/params managed parameters
LegacySubspace paramtypes.Subspace `optional:"true"`
}

type ModuleOutputs struct {
depinject.Out

IbcKeeper *keeper.Keeper
Module appmodule.AppModule
}

func ProvideModule(in ModuleInputs) ModuleOutputs {
// default to governance authority if not provided
authority := authtypes.NewModuleAddress(govtypes.ModuleName)
if in.Config.Authority != "" {
authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority)
}

keeper := keeper.NewKeeper(
in.Cdc,
in.Key,
in.LegacySubspace,
in.StakingKeeper,
in.UpgradeKeeper,
in.ScopedKeeper,
authority.String(),
)
m := NewAppModule(keeper)

return ModuleOutputs{IbcKeeper: keeper, Module: m}
}
Loading