github.com/daeglee/go-ethereum@v0.0.0-20190504220456-cad3e8d18e9b/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/ethereum/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  
    31  var (
    32  	app = utils.NewApp(gitCommit, "the evm command line interface")
    33  
    34  	DebugFlag = cli.BoolFlag{
    35  		Name:  "debug",
    36  		Usage: "output full trace logs",
    37  	}
    38  	MemProfileFlag = cli.StringFlag{
    39  		Name:  "memprofile",
    40  		Usage: "creates a memory profile at the given path",
    41  	}
    42  	CPUProfileFlag = cli.StringFlag{
    43  		Name:  "cpuprofile",
    44  		Usage: "creates a CPU profile at the given path",
    45  	}
    46  	StatDumpFlag = cli.BoolFlag{
    47  		Name:  "statdump",
    48  		Usage: "displays stack and heap memory information",
    49  	}
    50  	CodeFlag = cli.StringFlag{
    51  		Name:  "code",
    52  		Usage: "EVM code",
    53  	}
    54  	CodeFileFlag = cli.StringFlag{
    55  		Name:  "codefile",
    56  		Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
    57  	}
    58  	GasFlag = cli.Uint64Flag{
    59  		Name:  "gas",
    60  		Usage: "gas limit for the evm",
    61  		Value: 10000000000,
    62  	}
    63  	PriceFlag = utils.BigFlag{
    64  		Name:  "price",
    65  		Usage: "price set for the evm",
    66  		Value: new(big.Int),
    67  	}
    68  	ValueFlag = utils.BigFlag{
    69  		Name:  "value",
    70  		Usage: "value set for the evm",
    71  		Value: new(big.Int),
    72  	}
    73  	DumpFlag = cli.BoolFlag{
    74  		Name:  "dump",
    75  		Usage: "dumps the state after the run",
    76  	}
    77  	InputFlag = cli.StringFlag{
    78  		Name:  "input",
    79  		Usage: "input for the EVM",
    80  	}
    81  	VerbosityFlag = cli.IntFlag{
    82  		Name:  "verbosity",
    83  		Usage: "sets the verbosity level",
    84  	}
    85  	CreateFlag = cli.BoolFlag{
    86  		Name:  "create",
    87  		Usage: "indicates the action should be create rather than call",
    88  	}
    89  	GenesisFlag = cli.StringFlag{
    90  		Name:  "prestate",
    91  		Usage: "JSON file with prestate (genesis) config",
    92  	}
    93  	MachineFlag = cli.BoolFlag{
    94  		Name:  "json",
    95  		Usage: "output trace logs in machine readable format (json)",
    96  	}
    97  	SenderFlag = cli.StringFlag{
    98  		Name:  "sender",
    99  		Usage: "The transaction origin",
   100  	}
   101  	ReceiverFlag = cli.StringFlag{
   102  		Name:  "receiver",
   103  		Usage: "The transaction receiver (execution context)",
   104  	}
   105  	DisableMemoryFlag = cli.BoolFlag{
   106  		Name:  "nomemory",
   107  		Usage: "disable memory output",
   108  	}
   109  	DisableStackFlag = cli.BoolFlag{
   110  		Name:  "nostack",
   111  		Usage: "disable stack output",
   112  	}
   113  	EVMInterpreterFlag = cli.StringFlag{
   114  		Name:  "vm.evm",
   115  		Usage: "External EVM configuration (default = built-in interpreter)",
   116  		Value: "",
   117  	}
   118  )
   119  
   120  func init() {
   121  	app.Flags = []cli.Flag{
   122  		CreateFlag,
   123  		DebugFlag,
   124  		VerbosityFlag,
   125  		CodeFlag,
   126  		CodeFileFlag,
   127  		GasFlag,
   128  		PriceFlag,
   129  		ValueFlag,
   130  		DumpFlag,
   131  		InputFlag,
   132  		MemProfileFlag,
   133  		CPUProfileFlag,
   134  		StatDumpFlag,
   135  		GenesisFlag,
   136  		MachineFlag,
   137  		SenderFlag,
   138  		ReceiverFlag,
   139  		DisableMemoryFlag,
   140  		DisableStackFlag,
   141  		EVMInterpreterFlag,
   142  	}
   143  	app.Commands = []cli.Command{
   144  		compileCommand,
   145  		disasmCommand,
   146  		runCommand,
   147  		stateTestCommand,
   148  	}
   149  }
   150  
   151  func main() {
   152  	if err := app.Run(os.Args); err != nil {
   153  		fmt.Fprintln(os.Stderr, err)
   154  		os.Exit(1)
   155  	}
   156  }