main.go 3.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2014 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 13 14
// GNU General Public License for more details.
//
// 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/>.
obscuren's avatar
obscuren committed
16

17
// evm executes EVM code snippets.
obscuren's avatar
obscuren committed
18 19 20 21
package main

import (
	"fmt"
22
	"math/big"
obscuren's avatar
obscuren committed
23 24
	"os"

25
	"github.com/ethereum/go-ethereum/cmd/utils"
26
	"gopkg.in/urfave/cli.v1"
obscuren's avatar
obscuren committed
27 28
)

29
var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
30
var gitDate = ""
31

obscuren's avatar
obscuren committed
32
var (
33
	app = utils.NewApp(gitCommit, gitDate, "the evm command line interface")
34

35 36 37 38
	DebugFlag = cli.BoolFlag{
		Name:  "debug",
		Usage: "output full trace logs",
	}
39 40 41 42 43 44 45 46 47 48 49 50
	MemProfileFlag = cli.StringFlag{
		Name:  "memprofile",
		Usage: "creates a memory profile at the given path",
	}
	CPUProfileFlag = cli.StringFlag{
		Name:  "cpuprofile",
		Usage: "creates a CPU profile at the given path",
	}
	StatDumpFlag = cli.BoolFlag{
		Name:  "statdump",
		Usage: "displays stack and heap memory information",
	}
51 52 53 54
	CodeFlag = cli.StringFlag{
		Name:  "code",
		Usage: "EVM code",
	}
55 56
	CodeFileFlag = cli.StringFlag{
		Name:  "codefile",
57
		Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
58
	}
59
	GasFlag = cli.Uint64Flag{
60 61
		Name:  "gas",
		Usage: "gas limit for the evm",
62
		Value: 10000000000,
63
	}
64
	PriceFlag = utils.BigFlag{
65 66
		Name:  "price",
		Usage: "price set for the evm",
67
		Value: new(big.Int),
68
	}
69
	ValueFlag = utils.BigFlag{
70 71
		Name:  "value",
		Usage: "value set for the evm",
72
		Value: new(big.Int),
73 74 75 76 77 78 79 80 81
	}
	DumpFlag = cli.BoolFlag{
		Name:  "dump",
		Usage: "dumps the state after the run",
	}
	InputFlag = cli.StringFlag{
		Name:  "input",
		Usage: "input for the EVM",
	}
82 83 84 85
	InputFileFlag = cli.StringFlag{
		Name:  "inputfile",
		Usage: "file containing input for the EVM",
	}
86 87 88 89
	VerbosityFlag = cli.IntFlag{
		Name:  "verbosity",
		Usage: "sets the verbosity level",
	}
90 91 92 93
	BenchFlag = cli.BoolFlag{
		Name:  "bench",
		Usage: "benchmark the execution",
	}
94 95 96 97
	CreateFlag = cli.BoolFlag{
		Name:  "create",
		Usage: "indicates the action should be create rather than call",
	}
98 99 100 101 102 103 104 105 106 107 108 109
	GenesisFlag = cli.StringFlag{
		Name:  "prestate",
		Usage: "JSON file with prestate (genesis) config",
	}
	MachineFlag = cli.BoolFlag{
		Name:  "json",
		Usage: "output trace logs in machine readable format (json)",
	}
	SenderFlag = cli.StringFlag{
		Name:  "sender",
		Usage: "The transaction origin",
	}
110 111 112 113
	ReceiverFlag = cli.StringFlag{
		Name:  "receiver",
		Usage: "The transaction receiver (execution context)",
	}
114 115 116 117 118 119 120 121
	DisableMemoryFlag = cli.BoolFlag{
		Name:  "nomemory",
		Usage: "disable memory output",
	}
	DisableStackFlag = cli.BoolFlag{
		Name:  "nostack",
		Usage: "disable stack output",
	}
122 123 124 125 126
	EVMInterpreterFlag = cli.StringFlag{
		Name:  "vm.evm",
		Usage: "External EVM configuration (default = built-in interpreter)",
		Value: "",
	}
obscuren's avatar
obscuren committed
127 128
)

129 130
func init() {
	app.Flags = []cli.Flag{
131
		BenchFlag,
132
		CreateFlag,
133
		DebugFlag,
134
		VerbosityFlag,
135
		CodeFlag,
136
		CodeFileFlag,
137 138 139 140 141
		GasFlag,
		PriceFlag,
		ValueFlag,
		DumpFlag,
		InputFlag,
142
		InputFileFlag,
143 144 145
		MemProfileFlag,
		CPUProfileFlag,
		StatDumpFlag,
146 147 148
		GenesisFlag,
		MachineFlag,
		SenderFlag,
149
		ReceiverFlag,
150 151
		DisableMemoryFlag,
		DisableStackFlag,
152
		EVMInterpreterFlag,
153
	}
154 155
	app.Commands = []cli.Command{
		compileCommand,
156
		disasmCommand,
157
		runCommand,
158
		stateTestCommand,
159
	}
160
	cli.CommandHelpTemplate = utils.OriginCommandHelpTemplate
161 162 163 164 165 166 167
}

func main() {
	if err := app.Run(os.Args); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
obscuren's avatar
obscuren committed
168
}