github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/cmd/evm/main.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:32</date>
    10  //</624450067847188480>
    11  
    12  
    13  //EVM执行EVM代码段。
    14  package main
    15  
    16  import (
    17  	"fmt"
    18  	"math/big"
    19  	"os"
    20  
    21  	"github.com/ethereum/go-ethereum/cmd/utils"
    22  	"gopkg.in/urfave/cli.v1"
    23  )
    24  
    25  var gitCommit = "" //git sha1提交发布的哈希(通过链接器标志设置)
    26  
    27  var (
    28  	app = utils.NewApp(gitCommit, "the evm command line interface")
    29  
    30  	DebugFlag = cli.BoolFlag{
    31  		Name:  "debug",
    32  		Usage: "output full trace logs",
    33  	}
    34  	MemProfileFlag = cli.StringFlag{
    35  		Name:  "memprofile",
    36  		Usage: "creates a memory profile at the given path",
    37  	}
    38  	CPUProfileFlag = cli.StringFlag{
    39  		Name:  "cpuprofile",
    40  		Usage: "creates a CPU profile at the given path",
    41  	}
    42  	StatDumpFlag = cli.BoolFlag{
    43  		Name:  "statdump",
    44  		Usage: "displays stack and heap memory information",
    45  	}
    46  	CodeFlag = cli.StringFlag{
    47  		Name:  "code",
    48  		Usage: "EVM code",
    49  	}
    50  	CodeFileFlag = cli.StringFlag{
    51  		Name:  "codefile",
    52  		Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
    53  	}
    54  	GasFlag = cli.Uint64Flag{
    55  		Name:  "gas",
    56  		Usage: "gas limit for the evm",
    57  		Value: 10000000000,
    58  	}
    59  	PriceFlag = utils.BigFlag{
    60  		Name:  "price",
    61  		Usage: "price set for the evm",
    62  		Value: new(big.Int),
    63  	}
    64  	ValueFlag = utils.BigFlag{
    65  		Name:  "value",
    66  		Usage: "value set for the evm",
    67  		Value: new(big.Int),
    68  	}
    69  	DumpFlag = cli.BoolFlag{
    70  		Name:  "dump",
    71  		Usage: "dumps the state after the run",
    72  	}
    73  	InputFlag = cli.StringFlag{
    74  		Name:  "input",
    75  		Usage: "input for the EVM",
    76  	}
    77  	VerbosityFlag = cli.IntFlag{
    78  		Name:  "verbosity",
    79  		Usage: "sets the verbosity level",
    80  	}
    81  	CreateFlag = cli.BoolFlag{
    82  		Name:  "create",
    83  		Usage: "indicates the action should be create rather than call",
    84  	}
    85  	GenesisFlag = cli.StringFlag{
    86  		Name:  "prestate",
    87  		Usage: "JSON file with prestate (genesis) config",
    88  	}
    89  	MachineFlag = cli.BoolFlag{
    90  		Name:  "json",
    91  		Usage: "output trace logs in machine readable format (json)",
    92  	}
    93  	SenderFlag = cli.StringFlag{
    94  		Name:  "sender",
    95  		Usage: "The transaction origin",
    96  	}
    97  	ReceiverFlag = cli.StringFlag{
    98  		Name:  "receiver",
    99  		Usage: "The transaction receiver (execution context)",
   100  	}
   101  	DisableMemoryFlag = cli.BoolFlag{
   102  		Name:  "nomemory",
   103  		Usage: "disable memory output",
   104  	}
   105  	DisableStackFlag = cli.BoolFlag{
   106  		Name:  "nostack",
   107  		Usage: "disable stack output",
   108  	}
   109  	EVMInterpreterFlag = cli.StringFlag{
   110  		Name:  "vm.evm",
   111  		Usage: "External EVM configuration (default = built-in interpreter)",
   112  		Value: "",
   113  	}
   114  )
   115  
   116  func init() {
   117  	app.Flags = []cli.Flag{
   118  		CreateFlag,
   119  		DebugFlag,
   120  		VerbosityFlag,
   121  		CodeFlag,
   122  		CodeFileFlag,
   123  		GasFlag,
   124  		PriceFlag,
   125  		ValueFlag,
   126  		DumpFlag,
   127  		InputFlag,
   128  		MemProfileFlag,
   129  		CPUProfileFlag,
   130  		StatDumpFlag,
   131  		GenesisFlag,
   132  		MachineFlag,
   133  		SenderFlag,
   134  		ReceiverFlag,
   135  		DisableMemoryFlag,
   136  		DisableStackFlag,
   137  		EVMInterpreterFlag,
   138  	}
   139  	app.Commands = []cli.Command{
   140  		compileCommand,
   141  		disasmCommand,
   142  		runCommand,
   143  		stateTestCommand,
   144  	}
   145  }
   146  
   147  func main() {
   148  	if err := app.Run(os.Args); err != nil {
   149  		fmt.Fprintln(os.Stderr, err)
   150  		os.Exit(1)
   151  	}
   152  }
   153