github.com/zhiqiangxu/go-ethereum@v1.9.16-0.20210824055606-be91cfdebc48/cmd/evm/main.go (about) 1 // Copyright 2014 The go-ethereum Authors 2 // This file is part of go-ethereum. 3 // 4 // go-ethereum is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // go-ethereum is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. 16 17 // evm executes EVM code snippets. 18 package main 19 20 import ( 21 "fmt" 22 "math/big" 23 "os" 24 25 "github.com/zhiqiangxu/go-ethereum/cmd/utils" 26 "gopkg.in/urfave/cli.v1" 27 ) 28 29 var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags) 30 var gitDate = "" 31 32 var ( 33 app = utils.NewApp(gitCommit, gitDate, "the evm command line interface") 34 35 DebugFlag = cli.BoolFlag{ 36 Name: "debug", 37 Usage: "output full trace logs", 38 } 39 MemProfileFlag = cli.StringFlag{ 40 Name: "memprofile", 41 Usage: "creates a memory profile at the given path", 42 } 43 CPUProfileFlag = cli.StringFlag{ 44 Name: "cpuprofile", 45 Usage: "creates a CPU profile at the given path", 46 } 47 StatDumpFlag = cli.BoolFlag{ 48 Name: "statdump", 49 Usage: "displays stack and heap memory information", 50 } 51 CodeFlag = cli.StringFlag{ 52 Name: "code", 53 Usage: "EVM code", 54 } 55 CodeFileFlag = cli.StringFlag{ 56 Name: "codefile", 57 Usage: "File containing EVM code. If '-' is specified, code is read from stdin ", 58 } 59 GasFlag = cli.Uint64Flag{ 60 Name: "gas", 61 Usage: "gas limit for the evm", 62 Value: 10000000000, 63 } 64 PriceFlag = utils.BigFlag{ 65 Name: "price", 66 Usage: "price set for the evm", 67 Value: new(big.Int), 68 } 69 ValueFlag = utils.BigFlag{ 70 Name: "value", 71 Usage: "value set for the evm", 72 Value: new(big.Int), 73 } 74 DumpFlag = cli.BoolFlag{ 75 Name: "dump", 76 Usage: "dumps the state after the run", 77 } 78 InputFlag = cli.StringFlag{ 79 Name: "input", 80 Usage: "input for the EVM", 81 } 82 InputFileFlag = cli.StringFlag{ 83 Name: "inputfile", 84 Usage: "file containing input for the EVM", 85 } 86 VerbosityFlag = cli.IntFlag{ 87 Name: "verbosity", 88 Usage: "sets the verbosity level", 89 } 90 BenchFlag = cli.BoolFlag{ 91 Name: "bench", 92 Usage: "benchmark the execution", 93 } 94 CreateFlag = cli.BoolFlag{ 95 Name: "create", 96 Usage: "indicates the action should be create rather than call", 97 } 98 GenesisFlag = cli.StringFlag{ 99 Name: "prestate", 100 Usage: "JSON file with prestate (genesis) config", 101 } 102 MachineFlag = cli.BoolFlag{ 103 Name: "json", 104 Usage: "output trace logs in machine readable format (json)", 105 } 106 SenderFlag = cli.StringFlag{ 107 Name: "sender", 108 Usage: "The transaction origin", 109 } 110 ReceiverFlag = cli.StringFlag{ 111 Name: "receiver", 112 Usage: "The transaction receiver (execution context)", 113 } 114 DisableMemoryFlag = cli.BoolFlag{ 115 Name: "nomemory", 116 Usage: "disable memory output", 117 } 118 DisableStackFlag = cli.BoolFlag{ 119 Name: "nostack", 120 Usage: "disable stack output", 121 } 122 EVMInterpreterFlag = cli.StringFlag{ 123 Name: "vm.evm", 124 Usage: "External EVM configuration (default = built-in interpreter)", 125 Value: "", 126 } 127 ) 128 129 func init() { 130 app.Flags = []cli.Flag{ 131 BenchFlag, 132 CreateFlag, 133 DebugFlag, 134 VerbosityFlag, 135 CodeFlag, 136 CodeFileFlag, 137 GasFlag, 138 PriceFlag, 139 ValueFlag, 140 DumpFlag, 141 InputFlag, 142 InputFileFlag, 143 MemProfileFlag, 144 CPUProfileFlag, 145 StatDumpFlag, 146 GenesisFlag, 147 MachineFlag, 148 SenderFlag, 149 ReceiverFlag, 150 DisableMemoryFlag, 151 DisableStackFlag, 152 EVMInterpreterFlag, 153 } 154 app.Commands = []cli.Command{ 155 compileCommand, 156 disasmCommand, 157 runCommand, 158 stateTestCommand, 159 } 160 cli.CommandHelpTemplate = utils.OriginCommandHelpTemplate 161 } 162 163 func main() { 164 if err := app.Run(os.Args); err != nil { 165 fmt.Fprintln(os.Stderr, err) 166 os.Exit(1) 167 } 168 }