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(depinject): add support for core #4040

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
5 changes: 5 additions & 0 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ require (
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v1.0.0-rc.1 // indirect
github.com/cosmos/ibc-go/api v0.0.0 // indirect
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
Expand Down Expand Up @@ -230,6 +231,10 @@ replace (
// uncomment to use the local version of ibc-go, you will need to run `go mod tidy` in e2e directory.
replace github.com/cosmos/ibc-go/v8 => ../

replace github.com/cosmos/ibc-go/api => ../api

replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

replace cosmossdk.io/api/cosmos/capability => github.com/cosmos/ibc-go/modules/capability v1.0.0-rc1
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
cosmossdk.io/api v0.7.1
cosmossdk.io/client/v2 v2.0.0-20230818115413-c402c51a1508
cosmossdk.io/core v0.11.0
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.0
cosmossdk.io/log v1.2.1
cosmossdk.io/math v1.1.2
Expand All @@ -21,6 +22,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.50.0-rc.0.0.20230915171831-2196edacb99d
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/api v0.0.0
github.com/cosmos/ibc-go/modules/capability v1.0.0-rc5
github.com/cosmos/ics23/go v0.10.0
github.com/golang/protobuf v1.5.3
Expand All @@ -43,7 +45,6 @@ require (
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down Expand Up @@ -191,3 +192,5 @@ require (
)

replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

replace github.com/cosmos/ibc-go/api => ./api
58 changes: 58 additions & 0 deletions modules/core/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ import (
"github.com/spf13/cobra"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"

store "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/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"

modulev1 "github.com/cosmos/ibc-go/api/ibc/core/module/v1"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client"
clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
Expand Down Expand Up @@ -206,3 +213,54 @@ func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {
func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return nil
}

// App Wiring Setup

func init() {
appmodule.Register(&modulev1.Module{},
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}
}
2 changes: 1 addition & 1 deletion proto/buf.gen.gogo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: v1
plugins:
- name: gocosmos
out: ..
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types
opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types,Mcosmos/app/v1alpha1/module.proto=cosmossdk.io/api/cosmos/app/v1alpha1
- name: grpc-gateway
out: ..
opt: logtostderr=true,allow_colon_final_segments=true