diff --git a/x/distribution/module.go b/x/distribution/module.go index 24c783f3b22..c1203a03542 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "math/rand" gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -240,6 +241,7 @@ type distrOutputs struct { DistrKeeper keeper.Keeper Module runtime.AppModuleWrapper Hooks staking.StakingHooksWrapper + GovHandler v1beta1.RouteHandlerWrapper } func provideModule(in distrInputs) distrOutputs { @@ -250,5 +252,6 @@ func provideModule(in distrInputs) distrOutputs { DistrKeeper: k, Module: runtime.WrapAppModule(m), Hooks: staking.StakingHooksWrapper{StakingHooks: k.Hooks()}, + GovHandler: v1beta1.RouteHandlerWrapper{Handler: NewCommunityPoolSpendProposalHandler(k)}, } } diff --git a/x/gov/module.go b/x/gov/module.go index b93dab8f1f0..5751b02b8fd 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -4,11 +4,13 @@ package gov import ( "context" + "cosmossdk.io/core/appmodule" "encoding/json" "fmt" + "github.com/cosmos/cosmos-sdk/runtime" "math/rand" - "github.com/grpc-ecosystem/grpc-gateway/runtime" + gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -74,7 +76,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the gov module. -func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { +func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) { if err := v1.RegisterQueryHandlerClient(context.Background(), mux, v1.NewQueryClient(clientCtx)); err != nil { panic(err) } @@ -128,6 +130,34 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak types.AccountKeeper, } } +func init() { + appmodule.Register( + //&modulev1.Module{} + appmodule.Provide(provideModuleBasic, provideModule), + appmodule.Invoke(invokeAddRoutes)) +} + +func provideModuleBasic() runtime.AppModuleBasicWrapper { + return runtime.WrapAppModuleBasic(AppModuleBasic{}) +} + +func provideModule(cdc codec.Codec, ak types.AccountKeeper, bk types.BankKeeper) (runtime.AppModuleWrapper, v1beta1.RouteHandlerWrapper) { + // TODO + keeper := nil + return runtime.WrapAppModule(NewAppModule(cdc, keeper, ak, bk)), v1beta1.RouteHandlerWrapper{Handler: v1beta1.ProposalHandler} +} + +func invokeAddRoutes( // keeper GovKeeper, + routes map[string]v1beta1.RouteHandlerWrapper) { + router := v1beta1.NewRouter() + for s, wrapper := range routes { + router.AddRoute(s, wrapper.Handler) + } + // TODO + // set legacyHandler on govKeeper after construction. requires refactor. legacyRouter must not be sealed after construction + // but should be sealed after this operation +} + // Name returns the gov module's name. func (AppModule) Name() string { return types.ModuleName diff --git a/x/gov/types/v1beta1/content.go b/x/gov/types/v1beta1/content.go index a0ce70457aa..4c16b476b31 100644 --- a/x/gov/types/v1beta1/content.go +++ b/x/gov/types/v1beta1/content.go @@ -18,3 +18,9 @@ type Content interface { // Handler defines a function that handles a proposal after it has passed the // governance process. type Handler func(ctx sdk.Context, content Content) error + +// RouteHandlerWrapper is a wrapper for modules to inject RouteHandlers using depinject. +type RouteHandlerWrapper struct{ Handler } + +// IsOnePerModuleType implements the depinject.OnePerModuleType interface. +func (RouteHandlerWrapper) IsOnePerModuleType() {}