From 4ec14123861c9417d1a5fcbba7acaaeee15d9fa8 Mon Sep 17 00:00:00 2001 From: dudong2 Date: Sat, 3 Feb 2024 15:39:00 +0900 Subject: [PATCH] feat: apply autocli.go --- x/evm/autocli.go | 88 +++++++++++++++++++ x/evm/client/cli/query.go | 149 -------------------------------- x/evm/module.go | 8 +- x/feemarket/autocli.go | 48 ++++++++++ x/feemarket/client/cli/query.go | 131 ---------------------------- x/feemarket/module.go | 12 --- 6 files changed, 140 insertions(+), 296 deletions(-) create mode 100644 x/evm/autocli.go delete mode 100644 x/evm/client/cli/query.go create mode 100644 x/feemarket/autocli.go delete mode 100644 x/feemarket/client/cli/query.go diff --git a/x/evm/autocli.go b/x/evm/autocli.go new file mode 100644 index 0000000000..929fd06b84 --- /dev/null +++ b/x/evm/autocli.go @@ -0,0 +1,88 @@ +package evm + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + evmv1 "github.com/evmos/ethermint/api/ethermint/evm/v1" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: evmv1.Query_ServiceDesc.ServiceName, + EnhanceCustomCommand: false, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "params", + Short: "Get the evm params", + Long: "Get the evm parameter values.", + }, + { + RpcMethod: "Code", + Use: "code ADDRESS", + Short: "Gets code from an account", + Long: "Gets code from an account. If the height is not provided, it will use the latest height from context.", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}}, + }, + { + RpcMethod: "Storage", + Use: "storage ADDRESS KEY", + Short: "Gets storage for an account with a given key and height", + Long: "Gets storage for an account with a given key and height. If the height is not provided, it will use the latest height from context.", //nolint:lll + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "address"}, {ProtoField: "key"}}, + }, + { + RpcMethod: "Account", + Skip: true, + }, + { + RpcMethod: "CosmosAccount", + Skip: true, + }, + { + RpcMethod: "ValidatorAccount", + Skip: true, + }, + { + RpcMethod: "Balance", + Skip: true, + }, + { + RpcMethod: "EthCall", + Skip: true, + }, + { + RpcMethod: "EstimateGas", + Skip: true, + }, + { + RpcMethod: "TraceTx", + Skip: true, + }, + { + RpcMethod: "TraceBlock", + Skip: true, + }, + { + RpcMethod: "BaseFee", + Skip: true, + }, + }, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: evmv1.Msg_ServiceDesc.ServiceName, + EnhanceCustomCommand: true, // We provide costom RawTx in client/cli/tx.go + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "UpdateParams", + Skip: true, // skipped because authority gated + }, + { + RpcMethod: "EthereumTx", + Skip: true, + }, + }, + }, + } +} diff --git a/x/evm/client/cli/query.go b/x/evm/client/cli/query.go deleted file mode 100644 index bc3c6886b3..0000000000 --- a/x/evm/client/cli/query.go +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2021 Evmos Foundation -// This file is part of Evmos' Ethermint library. -// -// The Ethermint library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The Ethermint library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the Ethermint library. If not, see https://github.com/evmos/ethermint/blob/main/LICENSE -package cli - -import ( - rpctypes "github.com/evmos/ethermint/rpc/types" - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - - "github.com/evmos/ethermint/x/evm/types" -) - -// GetQueryCmd returns the parent command for all x/bank CLi query commands. -func GetQueryCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the evm module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - GetStorageCmd(), - GetCodeCmd(), - GetParamsCmd(), - ) - return cmd -} - -// GetStorageCmd queries a key in an accounts storage -func GetStorageCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "storage ADDRESS KEY", - Short: "Gets storage for an account with a given key and height", - Long: "Gets storage for an account with a given key and height. If the height is not provided, it will use the latest height from context.", //nolint:lll - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - address, err := accountToHex(args[0]) - if err != nil { - return err - } - - key := formatKeyToHash(args[1]) - - req := &types.QueryStorageRequest{ - Address: address, - Key: key, - } - - res, err := queryClient.Storage(rpctypes.ContextWithHeight(clientCtx.Height), req) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - return cmd -} - -// GetCodeCmd queries the code field of a given address -func GetCodeCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "code ADDRESS", - Short: "Gets code from an account", - Long: "Gets code from an account. If the height is not provided, it will use the latest height from context.", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - address, err := accountToHex(args[0]) - if err != nil { - return err - } - - req := &types.QueryCodeRequest{ - Address: address, - } - - res, err := queryClient.Code(rpctypes.ContextWithHeight(clientCtx.Height), req) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - return cmd -} - -// GetParamsCmd queries the fee market params -func GetParamsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "params", - Short: "Get the evm params", - Long: "Get the evm parameter values.", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, _ []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - return cmd -} diff --git a/x/evm/module.go b/x/evm/module.go index 9264448a83..2b1dfc21e2 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -93,10 +93,10 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd() } -// GetQueryCmd returns no root query command for the evm module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} +// // GetQueryCmd returns no root query command for the evm module. +// func (AppModuleBasic) GetQueryCmd() *cobra.Command { +// return cli.GetQueryCmd() +// } // RegisterInterfaces registers interfaces and implementations of the evm module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { diff --git a/x/feemarket/autocli.go b/x/feemarket/autocli.go new file mode 100644 index 0000000000..fa9b5d5e30 --- /dev/null +++ b/x/feemarket/autocli.go @@ -0,0 +1,48 @@ +package feemarket + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + feemarketv1 "github.com/evmos/ethermint/api/ethermint/feemarket/v1" +) + +// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface. +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + Service: feemarketv1.Query_ServiceDesc.ServiceName, + EnhanceCustomCommand: false, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Params", + Use: "params", + Short: "Get the fee market params", + Long: "Get the fee market parameter values.", + }, + { + RpcMethod: "BaseFee", + 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.`, + }, + { + RpcMethod: "BlockGas", + 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`, + }, + }, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: feemarketv1.Msg_ServiceDesc.ServiceName, + EnhanceCustomCommand: false, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "UpdateParams", + Skip: true, // skipped because authority gated + }, + }, + }, + } +} diff --git a/x/feemarket/client/cli/query.go b/x/feemarket/client/cli/query.go deleted file mode 100644 index 79c281f879..0000000000 --- a/x/feemarket/client/cli/query.go +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2021 Evmos Foundation -// This file is part of Evmos' Ethermint library. -// -// The Ethermint library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The Ethermint library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the Ethermint library. If not, see https://github.com/evmos/ethermint/blob/main/LICENSE -package cli - -import ( - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - - "github.com/evmos/ethermint/x/feemarket/types" -) - -// GetQueryCmd returns the parent command for all x/feemarket CLI query commands. -func GetQueryCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the fee market module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - GetBlockGasCmd(), - GetBaseFeeCmd(), - GetParamsCmd(), - ) - return cmd -} - -// GetBlockGasCmd queries the gas used in a block -func GetBlockGasCmd() *cobra.Command { - cmd := &cobra.Command{ - 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.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - ctx := cmd.Context() - res, err := queryClient.BlockGas(ctx, &types.QueryBlockGasRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - return cmd -} - -// GetParamsCmd queries the fee market params -func GetParamsCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "params", - Short: "Get the fee market params", - Long: "Get the fee market parameter values.", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, _ []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - return cmd -} - -// GetBaseFeeCmd queries the base fee at a given height -func GetBaseFeeCmd() *cobra.Command { - cmd := &cobra.Command{ - 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.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - ctx := cmd.Context() - res, err := queryClient.BaseFee(ctx, &types.QueryBaseFeeRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - return cmd -} diff --git a/x/feemarket/module.go b/x/feemarket/module.go index fd31e6a3b7..69aeb828bd 100644 --- a/x/feemarket/module.go +++ b/x/feemarket/module.go @@ -22,7 +22,6 @@ import ( "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" abci "github.com/cometbft/cometbft/abci/types" @@ -33,7 +32,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/evmos/ethermint/x/feemarket/client/cli" "github.com/evmos/ethermint/x/feemarket/keeper" "github.com/evmos/ethermint/x/feemarket/types" ) @@ -88,16 +86,6 @@ func (b AppModuleBasic) RegisterGRPCGatewayRoutes(c client.Context, serveMux *ru } } -// GetTxCmd returns the root tx command for the fee market module. -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return nil -} - -// GetQueryCmd returns no root query command for the fee market module. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} - // RegisterInterfaces registers interfaces and implementations of the fee market module. func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry)