Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions docs/docs/guide/02-hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,39 +227,7 @@ func (k Keeper) Hello(c context.Context, req *types.QueryHelloRequest) (*types.Q
```

- Save the file to restart your chain.
- In a web browser, visit the `hello` endpoint [http://localhost:1317/hello/hello/hello](http://localhost:1317/hello/hello/hello).

Because the query handlers are not yet registered with gRPC, you see a not implemented or localhost cannot connect error. This error is expected behavior, because you still need to register the query handlers.

## Register query handlers

Make the required changes to the `x/hello/module.go` file.

1. Add `"context"` to the list of packages in the import statement.

```go
import (
// ...

"context"

// ...
)
```

Do not save the file yet, you need to continue with these modifications.

1. Search for `RegisterGRPCGatewayRoutes`.

1. Register the query handlers:

```go
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}
```

2. After the chain has been started, visit [http://localhost:1317/hello/hello/hello](http://localhost:1317/hello/hello/hello) and see your text displayed:
- After the chain has been started, visit [http://localhost:1317/hello/hello/hello](http://localhost:1317/hello/hello/hello) and see your text displayed:

```json
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package <%= moduleName %>

import (
"context"
"encoding/json"
"fmt"
// this line is used by starport scaffolding # 1
Expand Down Expand Up @@ -71,7 +72,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
// this line is used by starport scaffolding # 2
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
}

// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module
Expand Down
17 changes: 0 additions & 17 deletions ignite/templates/typed/list/stargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func NewStargate(replacer placeholder.Replacer, opts *typed.Options) (*genny.Gen
)

g.RunFn(protoQueryModify(replacer, opts))
g.RunFn(moduleGRPCGatewayModify(replacer, opts))
g.RunFn(typesKeyModify(opts))
g.RunFn(clientCliQueryModify(replacer, opts))

Expand Down Expand Up @@ -243,22 +242,6 @@ message QueryAll%[2]vResponse {
}
}

func moduleGRPCGatewayModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "module.go")
f, err := r.Disk.Find(path)
if err != nil {
return err
}
replacement := `"context"`
content := replacer.ReplaceOnce(f.String(), typed.Placeholder, replacement)
replacement = `types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))`
content = replacer.ReplaceOnce(content, typed.Placeholder2, replacement)
newFile := genny.NewFileS(path, content)
return r.File(newFile)
}
}

func typesKeyModify(opts *typed.Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "types/keys.go")
Expand Down
19 changes: 0 additions & 19 deletions ignite/templates/typed/map/stargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func NewStargate(replacer placeholder.Replacer, opts *typed.Options) (*genny.Gen
)

g.RunFn(protoRPCModify(replacer, opts))
g.RunFn(moduleGRPCGatewayModify(replacer, opts))
g.RunFn(clientCliQueryModify(replacer, opts))
g.RunFn(genesisProtoModify(replacer, opts))
g.RunFn(genesisTypesModify(replacer, opts))
Expand Down Expand Up @@ -217,24 +216,6 @@ message QueryAll%[2]vResponse {
}
}

func moduleGRPCGatewayModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "module.go")
f, err := r.Disk.Find(path)
if err != nil {
return err
}
replacement := `"context"`
content := replacer.ReplaceOnce(f.String(), typed.Placeholder, replacement)

replacement = `types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))`
content = replacer.ReplaceOnce(content, typed.Placeholder2, replacement)

newFile := genny.NewFileS(path, content)
return r.File(newFile)
}
}

func clientCliQueryModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "client/cli/query.go")
Expand Down
19 changes: 0 additions & 19 deletions ignite/templates/typed/singleton/stargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func NewStargate(replacer placeholder.Replacer, opts *typed.Options) (*genny.Gen

g.RunFn(typesKeyModify(opts))
g.RunFn(protoRPCModify(replacer, opts))
g.RunFn(moduleGRPCGatewayModify(replacer, opts))
g.RunFn(clientCliQueryModify(replacer, opts))
g.RunFn(genesisProtoModify(replacer, opts))
g.RunFn(genesisTypesModify(replacer, opts))
Expand Down Expand Up @@ -152,24 +151,6 @@ message QueryGet%[2]vResponse {
}
}

func moduleGRPCGatewayModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "module.go")
f, err := r.Disk.Find(path)
if err != nil {
return err
}
replacement := `"context"`
content := replacer.ReplaceOnce(f.String(), typed.Placeholder, replacement)

replacement = `types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))`
content = replacer.ReplaceOnce(content, typed.Placeholder2, replacement)

newFile := genny.NewFileS(path, content)
return r.File(newFile)
}
}

func clientCliQueryModify(replacer placeholder.Replacer, opts *typed.Options) genny.RunFn {
return func(r *genny.Runner) error {
path := filepath.Join(opts.AppPath, "x", opts.ModuleName, "client/cli/query.go")
Expand Down