cmd/evm: Allow loading input from file (#20273)
Make it possible to load input from a file. Simlar to `--code` / `--codefile`, have `--input`/`--inputfile`.
This commit is contained in:
parent
738b51ae31
commit
9e71f55bfa
@ -79,6 +79,10 @@ var (
|
|||||||
Name: "input",
|
Name: "input",
|
||||||
Usage: "input for the EVM",
|
Usage: "input for the EVM",
|
||||||
}
|
}
|
||||||
|
InputFileFlag = cli.StringFlag{
|
||||||
|
Name: "inputfile",
|
||||||
|
Usage: "file containing input for the EVM",
|
||||||
|
}
|
||||||
VerbosityFlag = cli.IntFlag{
|
VerbosityFlag = cli.IntFlag{
|
||||||
Name: "verbosity",
|
Name: "verbosity",
|
||||||
Usage: "sets the verbosity level",
|
Usage: "sets the verbosity level",
|
||||||
@ -130,6 +134,7 @@ func init() {
|
|||||||
ValueFlag,
|
ValueFlag,
|
||||||
DumpFlag,
|
DumpFlag,
|
||||||
InputFlag,
|
InputFlag,
|
||||||
|
InputFileFlag,
|
||||||
MemProfileFlag,
|
MemProfileFlag,
|
||||||
CPUProfileFlag,
|
CPUProfileFlag,
|
||||||
StatDumpFlag,
|
StatDumpFlag,
|
||||||
|
@ -205,14 +205,24 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
tstart := time.Now()
|
tstart := time.Now()
|
||||||
var leftOverGas uint64
|
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) {
|
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)
|
ret, _, leftOverGas, err = runtime.Create(input, &runtimeConfig)
|
||||||
} else {
|
} else {
|
||||||
if len(code) > 0 {
|
if len(code) > 0 {
|
||||||
statedb.SetCode(receiver, code)
|
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)
|
execTime := time.Since(tstart)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user