Skip to content

Commit 9e71f55

Browse files
michaelforneyholiman
authored andcommitted
cmd/evm: Allow loading input from file (#20273)
Make it possible to load input from a file. Simlar to `--code` / `--codefile`, have `--input`/`--inputfile`.
1 parent 738b51a commit 9e71f55

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

cmd/evm/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ var (
7979
Name: "input",
8080
Usage: "input for the EVM",
8181
}
82+
InputFileFlag = cli.StringFlag{
83+
Name: "inputfile",
84+
Usage: "file containing input for the EVM",
85+
}
8286
VerbosityFlag = cli.IntFlag{
8387
Name: "verbosity",
8488
Usage: "sets the verbosity level",
@@ -130,6 +134,7 @@ func init() {
130134
ValueFlag,
131135
DumpFlag,
132136
InputFlag,
137+
InputFileFlag,
133138
MemProfileFlag,
134139
CPUProfileFlag,
135140
StatDumpFlag,

cmd/evm/runner.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,24 @@ func runCmd(ctx *cli.Context) error {
205205
}
206206
tstart := time.Now()
207207
var leftOverGas uint64
208+
var hexInput []byte
209+
if inputFileFlag := ctx.GlobalString(InputFileFlag.Name); inputFileFlag != "" {
210+
if hexInput, err = ioutil.ReadFile(inputFileFlag); err != nil {
211+
fmt.Printf("could not load input from file: %v\n", err)
212+
os.Exit(1)
213+
}
214+
} else {
215+
hexInput = []byte(ctx.GlobalString(InputFlag.Name))
216+
}
217+
input := common.FromHex(string(bytes.TrimSpace(hexInput)))
208218
if ctx.GlobalBool(CreateFlag.Name) {
209-
input := append(code, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...)
219+
input = append(code, input...)
210220
ret, _, leftOverGas, err = runtime.Create(input, &runtimeConfig)
211221
} else {
212222
if len(code) > 0 {
213223
statedb.SetCode(receiver, code)
214224
}
215-
ret, leftOverGas, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtimeConfig)
225+
ret, leftOverGas, err = runtime.Call(receiver, input, &runtimeConfig)
216226
}
217227
execTime := time.Since(tstart)
218228

0 commit comments

Comments
 (0)