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