feat!: integrate autocli and reflection services with simapp legacy (#13746)
* feat!: integrate autocli and reflection services with simapp legacy * rename alias * update UPGRADING.md Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
a3e1b99f6a
commit
74e9d542d2
10
UPGRADING.md
10
UPGRADING.md
|
@ -29,6 +29,16 @@ The `simapp` package **should not be imported in your own app**. Instead, you sh
|
||||||
SimApp's `app.go` is now using [App Wiring](https://docs.cosmos.network/main/building-apps/app-go), the dependency injection framework of the Cosmos SDK.
|
SimApp's `app.go` is now using [App Wiring](https://docs.cosmos.network/main/building-apps/app-go), the dependency injection framework of the Cosmos SDK.
|
||||||
This means that modules are injected directly into SimApp thanks to a [configuration file](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_config.go).
|
This means that modules are injected directly into SimApp thanks to a [configuration file](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_config.go).
|
||||||
The old behavior is preserved and can still be used, without the dependency injection framework, as shows [`app_legacy.go`](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_legacy.go).
|
The old behavior is preserved and can still be used, without the dependency injection framework, as shows [`app_legacy.go`](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_legacy.go).
|
||||||
|
If you are using a legacy `app.go` without dependency injection, add the following lines to your `app.go` in order to provide newer gRPC services:
|
||||||
|
```go
|
||||||
|
autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules))
|
||||||
|
|
||||||
|
reflectionSvc, err := runtimeservices.NewReflectionService()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)
|
||||||
|
```
|
||||||
|
|
||||||
#### Constructor
|
#### Constructor
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ import (
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
|
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
|
||||||
"cosmossdk.io/core/appmodule"
|
|
||||||
|
|
||||||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
|
@ -50,7 +48,6 @@ type App struct {
|
||||||
baseAppOptions []BaseAppOption
|
baseAppOptions []BaseAppOption
|
||||||
msgServiceRouter *baseapp.MsgServiceRouter
|
msgServiceRouter *baseapp.MsgServiceRouter
|
||||||
appConfig *appv1alpha1.Config
|
appConfig *appv1alpha1.Config
|
||||||
appModules map[string]appmodule.AppModule
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterModules registers the provided modules with the module manager and
|
// RegisterModules registers the provided modules with the module manager and
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (b BaseAppOption) IsManyPerContainerType() {}
|
||||||
func init() {
|
func init() {
|
||||||
appmodule.Register(&runtimev1alpha1.Module{},
|
appmodule.Register(&runtimev1alpha1.Module{},
|
||||||
appmodule.Provide(
|
appmodule.Provide(
|
||||||
ProvideCodecs,
|
Provide,
|
||||||
ProvideKVStoreKey,
|
ProvideKVStoreKey,
|
||||||
ProvideTransientStoreKey,
|
ProvideTransientStoreKey,
|
||||||
ProvideMemoryStoreKey,
|
ProvideMemoryStoreKey,
|
||||||
|
@ -38,7 +38,7 @@ func init() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (
|
func Provide(moduleBasics map[string]AppModuleBasicWrapper) (
|
||||||
codectypes.InterfaceRegistry,
|
codectypes.InterfaceRegistry,
|
||||||
codec.Codec,
|
codec.Codec,
|
||||||
*codec.LegacyAmino,
|
*codec.LegacyAmino,
|
||||||
|
@ -75,7 +75,7 @@ func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (
|
||||||
return interfaceRegistry, cdc, amino, app, cdc, msgServiceRouter
|
return interfaceRegistry, cdc, amino, app, cdc, msgServiceRouter
|
||||||
}
|
}
|
||||||
|
|
||||||
type appInputs struct {
|
type AppInputs struct {
|
||||||
depinject.In
|
depinject.In
|
||||||
|
|
||||||
AppConfig *appv1alpha1.Config
|
AppConfig *appv1alpha1.Config
|
||||||
|
@ -83,10 +83,9 @@ type appInputs struct {
|
||||||
AppBuilder *AppBuilder
|
AppBuilder *AppBuilder
|
||||||
Modules map[string]AppModuleWrapper
|
Modules map[string]AppModuleWrapper
|
||||||
BaseAppOptions []BaseAppOption
|
BaseAppOptions []BaseAppOption
|
||||||
AppModules map[string]appmodule.AppModule
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupAppBuilder(inputs appInputs) {
|
func SetupAppBuilder(inputs AppInputs) {
|
||||||
mm := &module.Manager{Modules: map[string]module.AppModule{}}
|
mm := &module.Manager{Modules: map[string]module.AppModule{}}
|
||||||
for name, wrapper := range inputs.Modules {
|
for name, wrapper := range inputs.Modules {
|
||||||
mm.Modules[name] = wrapper.AppModule
|
mm.Modules[name] = wrapper.AppModule
|
||||||
|
@ -96,7 +95,6 @@ func SetupAppBuilder(inputs appInputs) {
|
||||||
app.config = inputs.Config
|
app.config = inputs.Config
|
||||||
app.ModuleManager = mm
|
app.ModuleManager = mm
|
||||||
app.appConfig = inputs.AppConfig
|
app.appConfig = inputs.AppConfig
|
||||||
app.appModules = inputs.AppModules
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) {
|
func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) {
|
||||||
|
|
|
@ -5,12 +5,12 @@ import (
|
||||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||||
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/runtime/internal/services"
|
"github.com/cosmos/cosmos-sdk/runtime/services"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *App) registerRuntimeServices() error {
|
func (a *App) registerRuntimeServices() error {
|
||||||
appv1alpha1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAppQueryService(a.appConfig))
|
appv1alpha1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAppQueryService(a.appConfig))
|
||||||
autocliv1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAutoCLIQueryService(a.appModules))
|
autocliv1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAutoCLIQueryService(a.ModuleManager.Modules))
|
||||||
|
|
||||||
reflectionSvc, err := services.NewReflectionService()
|
reflectionSvc, err := services.NewReflectionService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,7 +4,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||||
"cosmossdk.io/core/appmodule"
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AutoCLIQueryService implements the cosmos.autocli.v1.Query service.
|
// AutoCLIQueryService implements the cosmos.autocli.v1.Query service.
|
||||||
|
@ -14,7 +15,7 @@ type AutoCLIQueryService struct {
|
||||||
moduleOptions map[string]*autocliv1.ModuleOptions
|
moduleOptions map[string]*autocliv1.ModuleOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQueryService {
|
func NewAutoCLIQueryService(appModules map[string]module.AppModule) *AutoCLIQueryService {
|
||||||
moduleOptions := map[string]*autocliv1.ModuleOptions{}
|
moduleOptions := map[string]*autocliv1.ModuleOptions{}
|
||||||
for modName, mod := range appModules {
|
for modName, mod := range appModules {
|
||||||
if autoCliMod, ok := mod.(interface {
|
if autoCliMod, ok := mod.(interface {
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||||
|
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
@ -23,6 +25,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
"github.com/cosmos/cosmos-sdk/runtime"
|
"github.com/cosmos/cosmos-sdk/runtime"
|
||||||
|
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/cosmos/cosmos-sdk/server/api"
|
"github.com/cosmos/cosmos-sdk/server/api"
|
||||||
"github.com/cosmos/cosmos-sdk/server/config"
|
"github.com/cosmos/cosmos-sdk/server/config"
|
||||||
|
@ -435,6 +438,14 @@ func NewSimApp(
|
||||||
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
|
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
|
||||||
app.ModuleManager.RegisterServices(app.configurator)
|
app.ModuleManager.RegisterServices(app.configurator)
|
||||||
|
|
||||||
|
autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules))
|
||||||
|
|
||||||
|
reflectionSvc, err := runtimeservices.NewReflectionService()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)
|
||||||
|
|
||||||
// add test gRPC service for testing gRPC queries in isolation
|
// add test gRPC service for testing gRPC queries in isolation
|
||||||
testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{})
|
testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue