refactor(core,stf): complete gas service + simplify deps (#21166)
This commit is contained in:
+8
-1
@@ -6,6 +6,7 @@ import (
|
||||
"slices"
|
||||
|
||||
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
@@ -77,7 +78,7 @@ func (a *App) RegisterModules(modules ...module.AppModule) error {
|
||||
|
||||
if mod, ok := appModule.(module.HasServices); ok {
|
||||
mod.RegisterServices(a.configurator)
|
||||
} else if module, ok := appModule.(appmodule.HasServices); ok {
|
||||
} else if module, ok := appModule.(hasServicesV1); ok {
|
||||
if err := module.RegisterServices(a.configurator); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -271,3 +272,9 @@ func (a *App) UnsafeFindStoreKey(storeKey string) storetypes.StoreKey {
|
||||
}
|
||||
|
||||
var _ servertypes.Application = &App{}
|
||||
|
||||
// hasServicesV1 is the interface for registering service in baseapp Cosmos SDK.
|
||||
// This API is part of core/appmodule but commented out for dependencies.
|
||||
type hasServicesV1 interface {
|
||||
RegisterServices(grpc.ServiceRegistrar) error
|
||||
}
|
||||
|
||||
@@ -54,7 +54,9 @@ func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) map[string
|
||||
mod.RegisterServices(cfg)
|
||||
}
|
||||
|
||||
if mod, ok := mod.(appmodule.HasServices); ok {
|
||||
if mod, ok := mod.(interface {
|
||||
RegisterServices(grpc.ServiceRegistrar) error
|
||||
}); ok {
|
||||
err := mod.RegisterServices(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@@ -425,7 +425,7 @@ func (m *MM[T]) RunMigrations(ctx context.Context, fromVM appmodulev2.VersionMap
|
||||
func (m *MM[T]) RegisterServices(app *App[T]) error {
|
||||
for _, module := range m.modules {
|
||||
// register msg + query
|
||||
if services, ok := module.(appmodule.HasServices); ok {
|
||||
if services, ok := module.(hasServicesV1); ok {
|
||||
if err := registerServices(services, app, protoregistry.GlobalFiles); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -554,7 +554,7 @@ func (m *MM[T]) assertNoForgottenModules(
|
||||
return nil
|
||||
}
|
||||
|
||||
func registerServices[T transaction.Tx](s appmodule.HasServices, app *App[T], registry *protoregistry.Files) error {
|
||||
func registerServices[T transaction.Tx](s hasServicesV1, app *App[T], registry *protoregistry.Files) error {
|
||||
c := &configurator{
|
||||
grpcQueryDecoders: map[string]func() gogoproto.Message{},
|
||||
stfQueryRouter: app.queryRouterBuilder,
|
||||
@@ -710,3 +710,9 @@ func defaultMigrationsOrder(modules []string) []string {
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// hasServicesV1 is the interface for registering service in baseapp Cosmos SDK.
|
||||
// This API is part of core/appmodule but commented out for dependencies.
|
||||
type hasServicesV1 interface {
|
||||
RegisterServices(grpc.ServiceRegistrar) error
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
||||
"cosmossdk.io/core/app"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/comet"
|
||||
"cosmossdk.io/core/genesis"
|
||||
@@ -33,7 +32,7 @@ import (
|
||||
|
||||
var (
|
||||
_ appmodulev2.AppModule = appModule[transaction.Tx]{}
|
||||
_ appmodule.HasServices = appModule[transaction.Tx]{}
|
||||
_ hasServicesV1 = appModule[transaction.Tx]{}
|
||||
)
|
||||
|
||||
type appModule[T transaction.Tx] struct {
|
||||
@@ -176,7 +175,12 @@ func ProvideModuleManager[T transaction.Tx](
|
||||
}
|
||||
|
||||
// ProvideEnvironment provides the environment for keeper modules, while maintaining backward compatibility and provide services directly as well.
|
||||
func ProvideEnvironment[T transaction.Tx](logger log.Logger, config *runtimev2.Module, key depinject.ModuleKey, appBuilder *AppBuilder[T]) (
|
||||
func ProvideEnvironment[T transaction.Tx](
|
||||
logger log.Logger,
|
||||
config *runtimev2.Module,
|
||||
key depinject.ModuleKey,
|
||||
appBuilder *AppBuilder[T],
|
||||
) (
|
||||
appmodulev2.Environment,
|
||||
store.KVStoreService,
|
||||
store.MemoryStoreService,
|
||||
|
||||
@@ -51,7 +51,10 @@ func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) (map[strin
|
||||
|
||||
// try to auto-discover options based on the last msg and query
|
||||
// services registered for the module
|
||||
if mod, ok := mod.(appmodule.HasServices); ok {
|
||||
// this supports the legacy core/appmodule v1 service registration
|
||||
if mod, ok := mod.(interface {
|
||||
RegisterServices(grpc.ServiceRegistrar) error
|
||||
}); ok {
|
||||
err := mod.RegisterServices(autoCliRegistrar)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user