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