gitee.com/liu-zhao234568/cntest@v1.0.0/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  	"gitee.com/liu-zhao234568/cntest/cmd/evm/internal/t8ntool"
    26  	"gitee.com/liu-zhao234568/cntest/cmd/utils"
    27  	"gitee.com/liu-zhao234568/cntest/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  )
   133  
   134  var stateTransitionCommand = cli.Command{
   135  	Name:    "transition",
   136  	Aliases: []string{"t8n"},
   137  	Usage:   "executes a full state transition",
   138  	Action:  t8ntool.Main,
   139  	Flags: []cli.Flag{
   140  		t8ntool.TraceFlag,
   141  		t8ntool.TraceDisableMemoryFlag,
   142  		t8ntool.TraceDisableStackFlag,
   143  		t8ntool.TraceDisableReturnDataFlag,
   144  		t8ntool.OutputBasedir,
   145  		t8ntool.OutputAllocFlag,
   146  		t8ntool.OutputResultFlag,
   147  		t8ntool.OutputBodyFlag,
   148  		t8ntool.InputAllocFlag,
   149  		t8ntool.InputEnvFlag,
   150  		t8ntool.InputTxsFlag,
   151  		t8ntool.ForknameFlag,
   152  		t8ntool.ChainIDFlag,
   153  		t8ntool.RewardFlag,
   154  		t8ntool.VerbosityFlag,
   155  	},
   156  }
   157  
   158  func init() {
   159  	app.Flags = []cli.Flag{
   160  		BenchFlag,
   161  		CreateFlag,
   162  		DebugFlag,
   163  		VerbosityFlag,
   164  		CodeFlag,
   165  		CodeFileFlag,
   166  		GasFlag,
   167  		PriceFlag,
   168  		ValueFlag,
   169  		DumpFlag,
   170  		InputFlag,
   171  		InputFileFlag,
   172  		MemProfileFlag,
   173  		CPUProfileFlag,
   174  		StatDumpFlag,
   175  		GenesisFlag,
   176  		MachineFlag,
   177  		SenderFlag,
   178  		ReceiverFlag,
   179  		DisableMemoryFlag,
   180  		DisableStackFlag,
   181  		DisableStorageFlag,
   182  		DisableReturnDataFlag,
   183  	}
   184  	app.Commands = []cli.Command{
   185  		compileCommand,
   186  		disasmCommand,
   187  		runCommand,
   188  		stateTestCommand,
   189  		stateTransitionCommand,
   190  	}
   191  	cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
   192  }
   193  
   194  func main() {
   195  	if err := app.Run(os.Args); err != nil {
   196  		code := 1
   197  		if ec, ok := err.(*t8ntool.NumberedError); ok {
   198  			code = ec.Code()
   199  		}
   200  		fmt.Fprintln(os.Stderr, err)
   201  		os.Exit(code)
   202  	}
   203  }