2022-12-16 09:48:38 +00:00
// 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
2019-07-25 20:38:55 +00:00
package cli
import (
2022-10-10 10:38:33 +00:00
rpctypes "github.com/cerc-io/laconicd/rpc/types"
2019-11-15 17:02:13 +00:00
"github.com/spf13/cobra"
2019-07-25 20:38:55 +00:00
"github.com/cosmos/cosmos-sdk/client"
2020-04-07 20:00:06 +00:00
"github.com/cosmos/cosmos-sdk/client/flags"
2019-11-15 17:02:13 +00:00
2022-09-07 06:36:11 +00:00
"github.com/cerc-io/laconicd/x/evm/types"
2019-07-25 20:38:55 +00:00
)
2021-04-17 10:00:07 +00:00
// GetQueryCmd returns the parent command for all x/bank CLi query commands.
func GetQueryCmd ( ) * cobra . Command {
cmd := & cobra . Command {
2019-07-25 20:38:55 +00:00
Use : types . ModuleName ,
Short : "Querying commands for the evm module" ,
DisableFlagParsing : true ,
SuggestionsMinimumDistance : 2 ,
RunE : client . ValidateCmd ,
}
2021-04-17 10:00:07 +00:00
cmd . AddCommand (
GetStorageCmd ( ) ,
GetCodeCmd ( ) ,
2022-10-10 10:38:33 +00:00
GetParamsCmd ( ) ,
2021-04-17 10:00:07 +00:00
)
return cmd
2019-07-25 20:38:55 +00:00
}
2021-04-17 10:00:07 +00:00
// GetStorageCmd queries a key in an accounts storage
func GetStorageCmd ( ) * cobra . Command {
cmd := & cobra . Command {
2022-10-31 17:47:57 +00:00
Use : "storage ADDRESS KEY" ,
2021-04-17 10:00:07 +00:00
Short : "Gets storage for an account with a given key and height" ,
2022-10-10 10:38:33 +00:00
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
2019-07-25 20:38:55 +00:00
Args : cobra . ExactArgs ( 2 ) ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2021-04-17 10:00:07 +00:00
clientCtx , err := client . GetClientQueryContext ( cmd )
if err != nil {
return err
}
2019-07-25 20:38:55 +00:00
2021-04-17 10:00:07 +00:00
queryClient := types . NewQueryClient ( clientCtx )
address , err := accountToHex ( args [ 0 ] )
2019-11-15 17:02:13 +00:00
if err != nil {
2021-04-17 10:00:07 +00:00
return err
2019-11-15 17:02:13 +00:00
}
key := formatKeyToHash ( args [ 1 ] )
2021-04-17 10:00:07 +00:00
req := & types . QueryStorageRequest {
Address : address ,
Key : key ,
}
2019-07-25 20:38:55 +00:00
2021-04-17 10:00:07 +00:00
res , err := queryClient . Storage ( rpctypes . ContextWithHeight ( clientCtx . Height ) , req )
2019-07-25 20:38:55 +00:00
if err != nil {
2021-04-17 10:00:07 +00:00
return err
2019-07-25 20:38:55 +00:00
}
2021-04-17 10:00:07 +00:00
return clientCtx . PrintProto ( res )
2019-07-25 20:38:55 +00:00
} ,
}
2021-04-17 10:00:07 +00:00
flags . AddQueryFlagsToCmd ( cmd )
return cmd
2019-07-25 20:38:55 +00:00
}
2021-04-17 10:00:07 +00:00
// GetCodeCmd queries the code field of a given address
func GetCodeCmd ( ) * cobra . Command {
cmd := & cobra . Command {
2022-10-31 17:47:57 +00:00
Use : "code ADDRESS" ,
2019-07-25 20:38:55 +00:00
Short : "Gets code from an account" ,
2021-04-17 10:00:07 +00:00
Long : "Gets code from an account. If the height is not provided, it will use the latest height from context." ,
2019-07-25 20:38:55 +00:00
Args : cobra . ExactArgs ( 1 ) ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2021-04-17 10:00:07 +00:00
clientCtx , err := client . GetClientQueryContext ( cmd )
if err != nil {
return err
}
2019-07-25 20:38:55 +00:00
2021-04-17 10:00:07 +00:00
queryClient := types . NewQueryClient ( clientCtx )
address , err := accountToHex ( args [ 0 ] )
2019-07-25 20:38:55 +00:00
if err != nil {
2021-04-17 10:00:07 +00:00
return err
2019-07-25 20:38:55 +00:00
}
2019-09-07 16:41:15 +00:00
2021-04-17 10:00:07 +00:00
req := & types . QueryCodeRequest {
Address : address ,
}
2019-09-07 16:41:15 +00:00
2021-04-17 10:00:07 +00:00
res , err := queryClient . Code ( rpctypes . ContextWithHeight ( clientCtx . Height ) , req )
2019-09-07 16:41:15 +00:00
if err != nil {
2021-04-17 10:00:07 +00:00
return err
2019-09-07 16:41:15 +00:00
}
2019-11-15 17:02:13 +00:00
2021-04-17 10:00:07 +00:00
return clientCtx . PrintProto ( res )
2019-09-07 16:41:15 +00:00
} ,
}
2021-04-17 10:00:07 +00:00
flags . AddQueryFlagsToCmd ( cmd )
return cmd
2019-09-07 16:41:15 +00:00
}
2022-10-10 10:38:33 +00:00
// 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
}