diff --git a/changelog.md b/changelog.md index 37a8b52ac3..fb3b938dca 100644 --- a/changelog.md +++ b/changelog.md @@ -48,7 +48,9 @@ - [#3183](https://github.com/ignite/cli/pull/3183/) Make config optional for init phase. - [#3224](https://github.com/ignite/cli/pull/3224) Remove grpc_* prefix from query files in scaffolded chains - [#3229](https://github.com/ignite/cli/pull/3229) Rename `campaign` to `project` in ignite network set of commands -- [#3244](https://github.com/ignite/cli/pull/3244) updated actions.yml for resolving deprecation message +- [#3244](https://github.com/ignite/cli/pull/3244) Update actions.yml for resolving deprecation message +- [#3337](https://github.com/ignite/cli/pull/3337) Remove `pkg/openapiconsole` import from scaffold template. +- [#3337](https://github.com/ignite/cli/pull/3337) Register`nodeservice` grpc in `app.go` template. ### Breaking Changes diff --git a/ignite/pkg/cosmosgen/generate_openapi.go b/ignite/pkg/cosmosgen/generate_openapi.go index 0db5746a1e..a7ed801f4c 100644 --- a/ignite/pkg/cosmosgen/generate_openapi.go +++ b/ignite/pkg/cosmosgen/generate_openapi.go @@ -113,7 +113,7 @@ func generateOpenAPISpec(g *generator) error { return nil } - // protoc openapi generator acts weird on conccurrent run, so do not use goroutines here. + // protoc openapi generator acts weird on concurrent run, so do not use goroutines here. if err := add(g.appPath, g.appModules); err != nil { return err } diff --git a/ignite/templates/app/files/app/app.go.plush b/ignite/templates/app/files/app/app.go.plush index 3effbd5d44..593b60a11c 100644 --- a/ignite/templates/app/files/app/app.go.plush +++ b/ignite/templates/app/files/app/app.go.plush @@ -3,12 +3,12 @@ package app import ( "fmt" "io" - "net/http" "os" "path/filepath" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" @@ -102,7 +102,6 @@ import ( "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" - "github.com/ignite/cli/ignite/pkg/openapiconsole" // this line is used by starport scaffolding # stargate/app/moduleImport @@ -492,7 +491,7 @@ func New( // this line is used by starport scaffolding # stargate/app/keeperDefinition - /**** IBC Routing ****/ + /**** IBC Routing ****/ // Sealing prevents other modules from creating scoped sub-keepers app.CapabilityKeeper.Seal() @@ -506,21 +505,21 @@ func New( /**** Module Hooks ****/ - // register hooks after all modules have been initialized + // register hooks after all modules have been initialized - app.StakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks( - // insert staking hooks receivers here - app.DistrKeeper.Hooks(), - app.SlashingKeeper.Hooks(), - ), - ) + app.StakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks( + // insert staking hooks receivers here + app.DistrKeeper.Hooks(), + app.SlashingKeeper.Hooks(), + ), + ) - app.GovKeeper.SetHooks( - govtypes.NewMultiGovHooks( - // insert governance hooks receivers here - ), - ) + app.GovKeeper.SetHooks( + govtypes.NewMultiGovHooks( + // insert governance hooks receivers here + ), + ) /**** Module Options ****/ @@ -815,13 +814,14 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // Register new tendermint queries routes from grpc-gateway. tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + // Register node gRPC service for grpc-gateway. + nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // Register grpc-gateway routes for all modules. ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) // register app's OpenAPI routes. - apiSvr.Router.Handle("/static/openapi.yml", http.FileServer(http.FS(docs.Docs))) - apiSvr.Router.HandleFunc("/", openapiconsole.Handler(Name, "/static/openapi.yml")) + docs.RegisterOpenAPIService(Name, apiSvr.Router) } // RegisterTxService implements the Application.RegisterTxService method. @@ -839,6 +839,11 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) { ) } +// RegisterNodeService implements the Application.RegisterNodeService method. +func (app *App) RegisterNodeService(clientCtx client.Context) { + nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter()) +} + // GetMaccPerms returns a copy of the module account permissions func GetMaccPerms() map[string][]string { dupMaccPerms := make(map[string][]string) diff --git a/ignite/templates/app/files/docs/docs.go.plush b/ignite/templates/app/files/docs/docs.go.plush index 1167d5657c..152c6cab71 100644 --- a/ignite/templates/app/files/docs/docs.go.plush +++ b/ignite/templates/app/files/docs/docs.go.plush @@ -1,6 +1,41 @@ package docs -import "embed" +import ( + "embed" + httptemplate "html/template" + "net/http" + + "github.com/gorilla/mux" +) + +const ( + apiFile = "/static/openapi.yml" + indexFile = "template/index.tpl" +) + //go:embed static -var Docs embed.FS +var Static embed.FS + +//go:embed template +var template embed.FS + +func RegisterOpenAPIService(appName string, rtr *mux.Router) { + rtr.Handle(apiFile, http.FileServer(http.FS(Static))) + rtr.HandleFunc("/", handler(appName)) +} + +// handler returns an http handler that servers OpenAPI console for an OpenAPI spec at specURL. +func handler(title string) http.HandlerFunc { + t, _ := httptemplate.ParseFS(template, indexFile) + + return func(w http.ResponseWriter, req *http.Request) { + t.Execute(w, struct { + Title string + URL string + }{ + title, + apiFile, + }) + } +} diff --git a/ignite/templates/app/files/docs/template/index.tpl b/ignite/templates/app/files/docs/template/index.tpl new file mode 100644 index 0000000000..ec098e82c2 --- /dev/null +++ b/ignite/templates/app/files/docs/template/index.tpl @@ -0,0 +1,28 @@ + + +
+ +