github.com/phillinzzz/newBsc@v1.1.6/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/phillinzzz/newBsc/cmd/evm/internal/t8ntool" 26 "github.com/phillinzzz/newBsc/cmd/utils" 27 "github.com/phillinzzz/newBsc/internal/flags" 28 "gopkg.in/urfave/cli.v1" 29 ) 30 31 var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags) 32 var gitDate = "" 33 34 var ( 35 app = flags.NewApp(gitCommit, gitDate, "the evm command line interface") 36 37 DebugFlag = cli.BoolFlag{ 38 Name: "debug", 39 Usage: "output full trace logs", 40 } 41 MemProfileFlag = cli.StringFlag{ 42 Name: "memprofile", 43 Usage: "creates a memory profile at the given path", 44 } 45 CPUProfileFlag = cli.StringFlag{ 46 Name: "cpuprofile", 47 Usage: "creates a CPU profile at the given path", 48 } 49 StatDumpFlag = cli.BoolFlag{ 50 Name: "statdump", 51 Usage: "displays stack and heap memory information", 52 } 53 CodeFlag = cli.StringFlag{ 54 Name: "code", 55 Usage: "EVM code", 56 } 57 CodeFileFlag = cli.StringFlag{ 58 Name: "codefile", 59 Usage: "File containing EVM code. If '-' is specified, code is read from stdin ", 60 } 61 GasFlag = cli.Uint64Flag{ 62 Name: "gas", 63 Usage: "gas limit for the evm", 64 Value: 10000000000, 65 } 66 PriceFlag = utils.BigFlag{ 67 Name: "price", 68 Usage: "price set for the evm", 69 Value: new(big.Int), 70 } 71 ValueFlag = utils.BigFlag{ 72 Name: "value", 73 Usage: "value set for the evm", 74 Value: new(big.Int), 75 } 76 DumpFlag = cli.BoolFlag{ 77 Name: "dump", 78 Usage: "dumps the state after the run", 79 } 80 InputFlag = cli.StringFlag{ 81 Name: "input", 82 Usage: "input for the EVM", 83 } 84 InputFileFlag = cli.StringFlag{ 85 Name: "inputfile", 86 Usage: "file containing input for the EVM", 87 } 88 VerbosityFlag = cli.IntFlag{ 89 Name: "verbosity", 90 Usage: "sets the verbosity level", 91 } 92 BenchFlag = cli.BoolFlag{ 93 Name: "bench", 94 Usage: "benchmark the execution", 95 } 96 CreateFlag = cli.BoolFlag{ 97 Name: "create", 98 Usage: "indicates the action should be create rather than call", 99 } 100 GenesisFlag = cli.StringFlag{ 101 Name: "prestate", 102 Usage: "JSON file with prestate (genesis) config", 103 } 104 MachineFlag = cli.BoolFlag{ 105 Name: "json", 106 Usage: "output trace logs in machine readable format (json)", 107 } 108 SenderFlag = cli.StringFlag{ 109 Name: "sender", 110 Usage: "The transaction origin", 111 } 112 ReceiverFlag = cli.StringFlag{ 113 Name: "receiver", 114 Usage: "The transaction receiver (execution context)", 115 } 116 DisableMemoryFlag = cli.BoolFlag{ 117 Name: "nomemory", 118 Usage: "disable memory output", 119 } 120 DisableStackFlag = cli.BoolFlag{ 121 Name: "nostack", 122 Usage: "disable stack output", 123 } 124 DisableStorageFlag = cli.BoolFlag{ 125 Name: "nostorage", 126 Usage: "disable storage output", 127 } 128 DisableReturnDataFlag = cli.BoolFlag{ 129 Name: "noreturndata", 130 Usage: "disable return data output", 131 } 132 EVMInterpreterFlag = cli.StringFlag{ 133 Name: "vm.evm", 134 Usage: "External EVM configuration (default = built-in interpreter)", 135 Value: "", 136 } 137 ) 138 139 var stateTransitionCommand = cli.Command{ 140 Name: "transition", 141 Aliases: []string{"t8n"}, 142 Usage: "executes a full state transition", 143 Action: t8ntool.Main, 144 Flags: []cli.Flag{ 145 t8ntool.TraceFlag, 146 t8ntool.TraceDisableMemoryFlag, 147 t8ntool.TraceDisableStackFlag, 148 t8ntool.TraceDisableReturnDataFlag, 149 t8ntool.OutputBasedir, 150 t8ntool.OutputAllocFlag, 151 t8ntool.OutputResultFlag, 152 t8ntool.OutputBodyFlag, 153 t8ntool.InputAllocFlag, 154 t8ntool.InputEnvFlag, 155 t8ntool.InputTxsFlag, 156 t8ntool.ForknameFlag, 157 t8ntool.ChainIDFlag, 158 t8ntool.RewardFlag, 159 t8ntool.VerbosityFlag, 160 }, 161 } 162 163 func init() { 164 app.Flags = []cli.Flag{ 165 BenchFlag, 166 CreateFlag, 167 DebugFlag, 168 VerbosityFlag, 169 CodeFlag, 170 CodeFileFlag, 171 GasFlag, 172 PriceFlag, 173 ValueFlag, 174 DumpFlag, 175 InputFlag, 176 InputFileFlag, 177 MemProfileFlag, 178 CPUProfileFlag, 179 StatDumpFlag, 180 GenesisFlag, 181 MachineFlag, 182 SenderFlag, 183 ReceiverFlag, 184 DisableMemoryFlag, 185 DisableStackFlag, 186 DisableStorageFlag, 187 DisableReturnDataFlag, 188 EVMInterpreterFlag, 189 } 190 app.Commands = []cli.Command{ 191 compileCommand, 192 disasmCommand, 193 runCommand, 194 stateTestCommand, 195 stateTransitionCommand, 196 } 197 cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate 198 } 199 200 func main() { 201 if err := app.Run(os.Args); err != nil { 202 code := 1 203 if ec, ok := err.(*t8ntool.NumberedError); ok { 204 code = ec.Code() 205 } 206 fmt.Fprintln(os.Stderr, err) 207 os.Exit(code) 208 } 209 }