Skip to content

Commit

Permalink
feat(gov): app-wiring in gov WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed Jun 27, 2022
1 parent f10f5e5 commit 166bcda
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -240,6 +241,7 @@ type distrOutputs struct {
DistrKeeper keeper.Keeper
Module runtime.AppModuleWrapper
Hooks staking.StakingHooksWrapper
GovHandler v1beta1.RouteHandlerWrapper
}

func provideModule(in distrInputs) distrOutputs {
Expand All @@ -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)},
}
}
34 changes: 32 additions & 2 deletions x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions x/gov/types/v1beta1/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

0 comments on commit 166bcda

Please sign in to comment.