-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
4,166 additions
and
647 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,89 @@ | ||
package evm | ||
|
||
import ( | ||
"fmt" | ||
|
||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" | ||
|
||
"github.com/cosmos/cosmos-sdk/version" | ||
evmv1 "github.com/initia-labs/minievm/api/minievm/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, | ||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{ | ||
{ | ||
RpcMethod: "Code", | ||
Use: "code [contract_addr]", | ||
Short: "Query contract code bytes", | ||
Example: fmt.Sprintf("%s query evm code 0x1", version.AppName), | ||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{ | ||
{ProtoField: "contract_addr"}, | ||
}, | ||
}, | ||
{ | ||
RpcMethod: "State", | ||
Use: "state [contract_addr] [key]", | ||
Short: "Query contract state", | ||
Example: fmt.Sprintf("%s query evm state 0x1 0x123...", version.AppName), | ||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{ | ||
{ProtoField: "contract_addr"}, | ||
{ProtoField: "key"}, | ||
}, | ||
}, | ||
{ | ||
RpcMethod: "ContractAddrByDenom", | ||
Use: "contract-addr-by-denom [denom]", | ||
Short: "Query corresponding contract address by denom", | ||
Alias: []string{"contract-addr"}, | ||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{ | ||
{ProtoField: "denom"}, | ||
}, | ||
}, | ||
{ | ||
RpcMethod: "Denom", | ||
Use: "denom [contract_addr]", | ||
Short: "Query corresponding denom by contract address", | ||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{ | ||
{ProtoField: "contract_addr"}, | ||
}, | ||
}, | ||
{ | ||
RpcMethod: "Params", | ||
Use: "params", | ||
Short: "Query the evm module params", | ||
}, | ||
{ | ||
RpcMethod: "Call", | ||
Skip: true, | ||
}, | ||
}, | ||
EnhanceCustomCommand: true, // We still have manual commands in evm that we want to keep | ||
}, | ||
Tx: &autocliv1.ServiceCommandDescriptor{ | ||
Service: evmv1.Msg_ServiceDesc.ServiceName, | ||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{ | ||
{ | ||
RpcMethod: "MsgCreate", | ||
Skip: true, | ||
}, | ||
{ | ||
RpcMethod: "MsgCreate2", | ||
Skip: true, | ||
}, | ||
{ | ||
RpcMethod: "MsgCall", | ||
Skip: true, | ||
}, | ||
{ | ||
RpcMethod: "UpdateParams", | ||
Skip: true, // skipped because authority gated | ||
}, | ||
}, | ||
EnhanceCustomCommand: false, // use custom commands only until v0.51 | ||
}, | ||
} | ||
} |
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,23 @@ | ||
package cli | ||
|
||
import ( | ||
flag "github.com/spf13/pflag" | ||
) | ||
|
||
const ( | ||
FlagTrace = "trace" | ||
FlagWithStorage = "with-storage" | ||
FlagWithMemory = "with-memory" | ||
FlagWithStack = "with-stack" | ||
FlagWithReturnData = "with-return-data" | ||
) | ||
|
||
func FlagTraceOptions() *flag.FlagSet { | ||
fs := flag.NewFlagSet("", flag.ContinueOnError) | ||
fs.Bool(FlagTrace, false, `Trace the execution of the transaction`) | ||
fs.Bool(FlagWithStorage, false, `Trace the storage of the contract`) | ||
fs.Bool(FlagWithMemory, false, `Trace the memory of the contract`) | ||
fs.Bool(FlagWithStack, false, `Trace the stack of the contract`) | ||
fs.Bool(FlagWithReturnData, false, `Trace the return data of the contract`) | ||
return fs | ||
} |
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,108 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/core/address" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
|
||
"github.com/initia-labs/minievm/x/evm/types" | ||
) | ||
|
||
func GetQueryCmd(ac address.Codec) *cobra.Command { | ||
queryCmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: "Querying commands for the move module", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
queryCmd.AddCommand( | ||
GetCmdCall(ac), | ||
) | ||
return queryCmd | ||
} | ||
|
||
func GetCmdCall(ac address.Codec) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "call [sender] [contract-addr] [input-hex-string]", | ||
Short: "Call deployed evm contract", | ||
Long: "Call deployed evm contract", | ||
Args: cobra.ExactArgs(3), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = ac.StringToBytes(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = types.ContractAddressFromString(ac, args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = hexutil.Decode(args[2]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
trace, err := cmd.Flags().GetBool(FlagTrace) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var traceOption *types.TraceOptions | ||
if trace { | ||
withMemory, err := cmd.Flags().GetBool(FlagWithMemory) | ||
if err != nil { | ||
return err | ||
} | ||
withStack, err := cmd.Flags().GetBool(FlagWithStack) | ||
if err != nil { | ||
return err | ||
} | ||
withStorage, err := cmd.Flags().GetBool(FlagWithStorage) | ||
if err != nil { | ||
return err | ||
} | ||
withReturnData, err := cmd.Flags().GetBool(FlagWithReturnData) | ||
if err != nil { | ||
return err | ||
} | ||
traceOption = &types.TraceOptions{ | ||
WithMemory: withMemory, | ||
WithStack: withStack, | ||
WithStorage: withStorage, | ||
WithReturnData: withReturnData, | ||
} | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
res, err := queryClient.Call( | ||
context.Background(), | ||
&types.QueryCallRequest{ | ||
Sender: args[0], | ||
ContractAddr: args[1], | ||
Input: args[2], | ||
TraceOptions: traceOption, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
cmd.Flags().AddFlagSet(FlagTraceOptions()) | ||
flags.AddQueryFlagsToCmd(cmd) | ||
return cmd | ||
} |
Oops, something went wrong.