From 9e71f55bfab91a26f5cfc06f0a4e48839b25f249 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 17 Nov 2019 06:45:54 -0800 Subject: [PATCH] cmd/evm: Allow loading input from file (#20273) Make it possible to load input from a file. Simlar to `--code` / `--codefile`, have `--input`/`--inputfile`. --- cmd/evm/main.go | 5 +++++ cmd/evm/runner.go | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/evm/main.go b/cmd/evm/main.go index a5159c6b7..5b8b950ab 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -79,6 +79,10 @@ var ( Name: "input", Usage: "input for the EVM", } + InputFileFlag = cli.StringFlag{ + Name: "inputfile", + Usage: "file containing input for the EVM", + } VerbosityFlag = cli.IntFlag{ Name: "verbosity", Usage: "sets the verbosity level", @@ -130,6 +134,7 @@ func init() { ValueFlag, DumpFlag, InputFlag, + InputFileFlag, MemProfileFlag, CPUProfileFlag, StatDumpFlag, diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index 3cbdcad01..cecbf3606 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -205,14 +205,24 @@ func runCmd(ctx *cli.Context) error { } tstart := time.Now() var leftOverGas uint64 + var hexInput []byte + if inputFileFlag := ctx.GlobalString(InputFileFlag.Name); inputFileFlag != "" { + if hexInput, err = ioutil.ReadFile(inputFileFlag); err != nil { + fmt.Printf("could not load input from file: %v\n", err) + os.Exit(1) + } + } else { + hexInput = []byte(ctx.GlobalString(InputFlag.Name)) + } + input := common.FromHex(string(bytes.TrimSpace(hexInput))) if ctx.GlobalBool(CreateFlag.Name) { - input := append(code, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...) + input = append(code, input...) ret, _, leftOverGas, err = runtime.Create(input, &runtimeConfig) } else { if len(code) > 0 { statedb.SetCode(receiver, code) } - ret, leftOverGas, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtimeConfig) + ret, leftOverGas, err = runtime.Call(receiver, input, &runtimeConfig) } execTime := time.Since(tstart)