Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Problem: feemarket's query cli has redundant height parameter #1230

Merged
merged 1 commit into from
Aug 10, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (feemarket) [\#1165](https://github.com/evmos/ethermint/pull/1165) Add hint in specs about different gas terminology for gas in Cosmos and Ethereum.
* (cli) [#1226](https://github.com/evmos/ethermint/pull/1226) Add custom app db backend flag.
* (cli) [#1230](https://github.com/evmos/ethermint/pull/1230) Remove redundant positional height parameter from feemarket's query cli.

### Bug Fixes

Expand Down
41 changes: 6 additions & 35 deletions x/feemarket/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package cli

import (
"context"
"fmt"
"strconv"

"github.com/spf13/cobra"
"google.golang.org/grpc/metadata"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"

"github.com/evmos/ethermint/x/feemarket/types"
)
Expand All @@ -36,27 +30,20 @@ func GetQueryCmd() *cobra.Command {
// GetBlockGasCmd queries the gas used in a block
func GetBlockGasCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "block-gas [height]",
Use: "block-gas",
Short: "Get the block gas used at a given block height",
Long: `Get the block gas used at a given block height.
If the height is not provided, it will use the latest height from context`,
Args: cobra.RangeArgs(0, 1),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

ctx := cmd.Context()
if len(args) == 1 {
ctx, err = getContextHeight(ctx, args[0])
if err != nil {
return err
}
}

queryClient := types.NewQueryClient(clientCtx)

ctx := cmd.Context()
res, err := queryClient.BlockGas(ctx, &types.QueryBlockGasRequest{})
if err != nil {
return err
Expand Down Expand Up @@ -101,27 +88,20 @@ func GetParamsCmd() *cobra.Command {
// GetBaseFeeCmd queries the base fee at a given height
func GetBaseFeeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "base-fee [height]",
Use: "base-fee",
Short: "Get the base fee amount at a given block height",
Long: `Get the base fee amount at a given block height.
If the height is not provided, it will use the latest height from context.`,
Args: cobra.RangeArgs(0, 1),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

ctx := cmd.Context()
if len(args) == 1 {
ctx, err = getContextHeight(ctx, args[0])
if err != nil {
return err
}
}

queryClient := types.NewQueryClient(clientCtx)

ctx := cmd.Context()
res, err := queryClient.BaseFee(ctx, &types.QueryBaseFeeRequest{})
if err != nil {
return err
Expand All @@ -134,12 +114,3 @@ If the height is not provided, it will use the latest height from context.`,
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func getContextHeight(ctx context.Context, height string) (context.Context, error) {
_, err := strconv.ParseInt(height, 10, 64)
if err != nil {
return ctx, fmt.Errorf("invalid height: %w", err)
}

return metadata.AppendToOutgoingContext(ctx, grpctypes.GRPCBlockHeightHeader, height), nil
}