Skip to content

Commit

Permalink
fix: make panic when GRPCGateway handler is not registered correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tkxkd0159 authored Oct 18, 2022
1 parent 3e46698 commit ef55766
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth,bank,foundation,wasm) [\#691](https://github.com/line/lbm-sdk/pull/691) change AccAddressFromBech32 to MustAccAddressFromBech32
* (x/wasm) [\#690](https://github.com/line/lbm-sdk/pull/690) fix to prevent accepting file name
* (cli) [\#708](https://github.com/line/lbm-sdk/pull/708) In CLI, allow 1 SIGN_MODE_DIRECT signer in transactions with multiple signers.
* (x/modules) [\#722](https://github.com/line/lbm-sdk/pull/722) Check error for `RegisterQueryHandlerClient` in all modules `RegisterGRPCGatewayRoutes`
* (x/bank) [\#716](https://github.com/line/lbm-sdk/pull/716) remove useless DenomMetadata key function


Expand Down
4 changes: 3 additions & 1 deletion x/auth/tx/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ func RegisterTxService(
// RegisterGRPCGatewayRoutes mounts the tx service's GRPC-gateway routes on the
// given Mux.
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) {
txtypes.RegisterServiceHandlerClient(context.Background(), mux, txtypes.NewServiceClient(clientConn))
if err := txtypes.RegisterServiceHandlerClient(context.Background(), mux, txtypes.NewServiceClient(clientConn)); err != nil {
panic(err)
}
}

func parseOrderBy(orderBy txtypes.OrderBy) string {
Expand Down
4 changes: 3 additions & 1 deletion x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, r *mux.Rou

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the authz module.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) {
authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx))
if err := authz.RegisterQueryHandlerClient(context.Background(), mux, authz.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetQueryCmd returns the cli query commands for the authz module
Expand Down
4 changes: 3 additions & 1 deletion x/bank/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bank module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns the root tx command for the bank module.
Expand Down
4 changes: 3 additions & 1 deletion x/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx sdkclient.Context, rtr *mux.R

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the distribution module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx sdkclient.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns the root tx command for the distribution module.
Expand Down
4 changes: 3 additions & 1 deletion x/evidence/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the evidence module.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns the evidence module's root tx command.
Expand Down
4 changes: 3 additions & 1 deletion x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ func (a AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Ro

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the gov module.
func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns the root tx command for the gov module.
Expand Down
13 changes: 9 additions & 4 deletions x/ibc/applications/27-interchain-accounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
abci "github.com/line/ostracon/abci/types"
"github.com/spf13/cobra"

"github.com/line/lbm-sdk/client"
"github.com/line/lbm-sdk/codec"
codectypes "github.com/line/lbm-sdk/codec/types"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/types/module"
abci "github.com/line/ostracon/abci/types"
"github.com/spf13/cobra"

"github.com/line/lbm-sdk/x/ibc/applications/27-interchain-accounts/client/cli"
"github.com/line/lbm-sdk/x/ibc/applications/27-interchain-accounts/controller"
Expand Down Expand Up @@ -73,8 +74,12 @@ func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) {

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the interchain accounts module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
controllertypes.RegisterQueryHandlerClient(context.Background(), mux, controllertypes.NewQueryClient(clientCtx))
hosttypes.RegisterQueryHandlerClient(context.Background(), mux, hosttypes.NewQueryClient(clientCtx))
if err := controllertypes.RegisterQueryHandlerClient(context.Background(), mux, controllertypes.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
if err := hosttypes.RegisterQueryHandlerClient(context.Background(), mux, hosttypes.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd implements AppModuleBasic interface
Expand Down
9 changes: 6 additions & 3 deletions x/ibc/applications/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (

"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
abci "github.com/line/ostracon/abci/types"
"github.com/spf13/cobra"

"github.com/line/lbm-sdk/client"
"github.com/line/lbm-sdk/codec"
codectypes "github.com/line/lbm-sdk/codec/types"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/types/module"
simtypes "github.com/line/lbm-sdk/types/simulation"
abci "github.com/line/ostracon/abci/types"
"github.com/spf13/cobra"

"github.com/line/lbm-sdk/x/ibc/applications/transfer/client/cli"
"github.com/line/lbm-sdk/x/ibc/applications/transfer/keeper"
Expand Down Expand Up @@ -70,7 +71,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc-transfer module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd implements AppModuleBasic interface
Expand Down
17 changes: 12 additions & 5 deletions x/ibc/core/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (

"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
abci "github.com/line/ostracon/abci/types"
"github.com/spf13/cobra"

"github.com/line/lbm-sdk/client"
"github.com/line/lbm-sdk/codec"
codectypes "github.com/line/lbm-sdk/codec/types"
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/types/module"
simtypes "github.com/line/lbm-sdk/types/simulation"
abci "github.com/line/ostracon/abci/types"
"github.com/spf13/cobra"

ibcclient "github.com/line/lbm-sdk/x/ibc/core/02-client"
clientkeeper "github.com/line/lbm-sdk/x/ibc/core/02-client/keeper"
Expand Down Expand Up @@ -69,9 +70,15 @@ func (AppModuleBasic) RegisterRESTRoutes(client.Context, *mux.Router) {}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the ibc module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
clienttypes.RegisterQueryHandlerClient(context.Background(), mux, clienttypes.NewQueryClient(clientCtx))
connectiontypes.RegisterQueryHandlerClient(context.Background(), mux, connectiontypes.NewQueryClient(clientCtx))
channeltypes.RegisterQueryHandlerClient(context.Background(), mux, channeltypes.NewQueryClient(clientCtx))
if err := clienttypes.RegisterQueryHandlerClient(context.Background(), mux, clienttypes.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
if err := connectiontypes.RegisterQueryHandlerClient(context.Background(), mux, connectiontypes.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
if err := channeltypes.RegisterQueryHandlerClient(context.Background(), mux, channeltypes.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns the root tx command for the ibc module.
Expand Down
4 changes: 3 additions & 1 deletion x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the mint module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}

}

Expand Down
4 changes: 3 additions & 1 deletion x/params/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {}

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the params module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
proposal.RegisterQueryHandlerClient(context.Background(), mux, proposal.NewQueryClient(clientCtx))
if err := proposal.RegisterQueryHandlerClient(context.Background(), mux, proposal.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns no root tx command for the params module.
Expand Down
4 changes: 3 additions & 1 deletion x/slashing/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the slashig module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns the root tx command for the slashing module.
Expand Down
4 changes: 3 additions & 1 deletion x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Rout

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the staking module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns the root tx command for the staking module.
Expand Down
4 changes: 3 additions & 1 deletion x/upgrade/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, r *mux.Router

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the upgrade module.
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetQueryCmd returns the cli query commands for this module
Expand Down

0 comments on commit ef55766

Please sign in to comment.