Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
cmd/evm: Allow loading input from file (ethereum#20273)
Browse files Browse the repository at this point in the history
Make it possible to load input from a file. Simlar to `--code` / `--codefile`, have `--input`/`--inputfile`.
  • Loading branch information
michaelforney authored and elizabethengelman committed Dec 20, 2019
1 parent ff5d3b6 commit fe05134
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/evm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -130,6 +134,7 @@ func init() {
ValueFlag,
DumpFlag,
InputFlag,
InputFileFlag,
MemProfileFlag,
CPUProfileFlag,
StatDumpFlag,
Expand Down
14 changes: 12 additions & 2 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit fe05134

Please sign in to comment.