forked from evmos/ethermint
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: evm query store, code use custom query args
- Loading branch information
Showing
4 changed files
with
124 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// 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(), | ||
) | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters