Skip to content

Commit

Permalink
Merge PR: evm query params (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovers authored Dec 1, 2020
1 parent 5e0bab6 commit ec04c81
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions x/evm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -26,6 +27,7 @@ func GetQueryCmd(moduleName string, cdc *codec.Codec) *cobra.Command {
evmQueryCmd.AddCommand(flags.GetCommands(
GetCmdGetStorageAt(moduleName, cdc),
GetCmdGetCode(moduleName, cdc),
GetCmdQueryParams(moduleName, cdc),
)...)
return evmQueryCmd
}
Expand Down Expand Up @@ -86,3 +88,29 @@ func GetCmdGetCode(queryRoute string, cdc *codec.Codec) *cobra.Command {
},
}
}

// GetCmdQueryParams implements the query params command.
func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "params",
Short: "Query all the modifiable parameters of gov proposal",
Long: strings.TrimSpace(`Query the all the parameters for the governance process:
$ okexchaincli query evm params
`),
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

route := fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryParameters)
bz, _, err := cliCtx.QueryWithData(route, nil)
if err != nil {
return err
}

var params types.Params
cdc.MustUnmarshalJSON(bz, &params)
return cliCtx.PrintOutput(params)
},
}
}
11 changes: 11 additions & 0 deletions x/evm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func NewQuerier(keeper Keeper) sdk.Querier {
return queryAccount(ctx, path, keeper)
case types.QueryExportAccount:
return queryExportAccount(ctx, path, keeper)
case types.QueryParameters:
return queryParams(ctx, keeper)
default:
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "unknown query endpoint")
}
Expand Down Expand Up @@ -230,3 +232,12 @@ func queryExportAccount(ctx sdk.Context, path []string, keeper Keeper) ([]byte,

return bz, nil
}

func queryParams(ctx sdk.Context, keeper Keeper) (res []byte, err sdk.Error) {
params := keeper.GetParams(ctx)
res, errUnmarshal := codec.MarshalJSONIndent(types.ModuleCdc, params)
if errUnmarshal != nil {
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal result to JSON", errUnmarshal.Error()))
}
return res, nil
}
2 changes: 2 additions & 0 deletions x/evm/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
QueryLogs = "logs"
QueryAccount = "account"
QueryExportAccount = "exportAccount"
// QueryParameters defines QueryParameters = "params" query route path
QueryParameters = "params"
)

// QueryResProtocolVersion is response type for protocol version query
Expand Down

0 comments on commit ec04c81

Please sign in to comment.