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:
Aaron Craelius 2022-11-08 07:32:49 -05:00 committed by GitHub
parent a3e1b99f6a
commit 74e9d542d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 13 deletions

View File

@ -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.
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).
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

View File

@ -8,8 +8,6 @@ import (
"golang.org/x/exp/slices"
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
"cosmossdk.io/core/appmodule"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"github.com/cosmos/cosmos-sdk/baseapp"
@ -50,7 +48,6 @@ type App struct {
baseAppOptions []BaseAppOption
msgServiceRouter *baseapp.MsgServiceRouter
appConfig *appv1alpha1.Config
appModules map[string]appmodule.AppModule
}
// RegisterModules registers the provided modules with the module manager and

View File

@ -28,7 +28,7 @@ func (b BaseAppOption) IsManyPerContainerType() {}
func init() {
appmodule.Register(&runtimev1alpha1.Module{},
appmodule.Provide(
ProvideCodecs,
Provide,
ProvideKVStoreKey,
ProvideTransientStoreKey,
ProvideMemoryStoreKey,
@ -38,7 +38,7 @@ func init() {
)
}
func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (
func Provide(moduleBasics map[string]AppModuleBasicWrapper) (
codectypes.InterfaceRegistry,
codec.Codec,
*codec.LegacyAmino,
@ -75,7 +75,7 @@ func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (
return interfaceRegistry, cdc, amino, app, cdc, msgServiceRouter
}
type appInputs struct {
type AppInputs struct {
depinject.In
AppConfig *appv1alpha1.Config
@ -83,10 +83,9 @@ type appInputs struct {
AppBuilder *AppBuilder
Modules map[string]AppModuleWrapper
BaseAppOptions []BaseAppOption
AppModules map[string]appmodule.AppModule
}
func SetupAppBuilder(inputs appInputs) {
func SetupAppBuilder(inputs AppInputs) {
mm := &module.Manager{Modules: map[string]module.AppModule{}}
for name, wrapper := range inputs.Modules {
mm.Modules[name] = wrapper.AppModule
@ -96,7 +95,6 @@ func SetupAppBuilder(inputs appInputs) {
app.config = inputs.Config
app.ModuleManager = mm
app.appConfig = inputs.AppConfig
app.appModules = inputs.AppModules
}
func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) {

View File

@ -5,12 +5,12 @@ import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/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 {
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()
if err != nil {

View File

@ -4,7 +4,8 @@ import (
"context"
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.
@ -14,7 +15,7 @@ type AutoCLIQueryService struct {
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{}
for modName, mod := range appModules {
if autoCliMod, ok := mod.(interface {

View File

@ -9,6 +9,8 @@ import (
"os"
"path/filepath"
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
@ -23,6 +25,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"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/api"
"github.com/cosmos/cosmos-sdk/server/config"
@ -435,6 +438,14 @@ func NewSimApp(
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
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
testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{})