cmd/evm: evm input minor fixes (#19740)
* cmd/evm: evm input minor fixes, handle prefix, validate length, fixes #18041 * cmd/evm: remove whitespace
This commit is contained in:
parent
1da5e0ebb0
commit
2ca89ea479
@ -17,7 +17,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -121,12 +120,16 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
ret []byte
|
ret []byte
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
codeFileFlag := ctx.GlobalString(CodeFileFlag.Name)
|
||||||
|
codeFlag := ctx.GlobalString(CodeFlag.Name)
|
||||||
|
|
||||||
// The '--code' or '--codefile' flag overrides code in state
|
// The '--code' or '--codefile' flag overrides code in state
|
||||||
if ctx.GlobalString(CodeFileFlag.Name) != "" {
|
if codeFileFlag != "" || codeFlag != "" {
|
||||||
var hexcode []byte
|
var hexcode []byte
|
||||||
|
if codeFileFlag != "" {
|
||||||
var err error
|
var err error
|
||||||
// If - is specified, it means that code comes from stdin
|
// If - is specified, it means that code comes from stdin
|
||||||
if ctx.GlobalString(CodeFileFlag.Name) == "-" {
|
if codeFileFlag == "-" {
|
||||||
//Try reading from stdin
|
//Try reading from stdin
|
||||||
if hexcode, err = ioutil.ReadAll(os.Stdin); err != nil {
|
if hexcode, err = ioutil.ReadAll(os.Stdin); err != nil {
|
||||||
fmt.Printf("Could not load code from stdin: %v\n", err)
|
fmt.Printf("Could not load code from stdin: %v\n", err)
|
||||||
@ -134,15 +137,19 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Codefile with hex assembly
|
// Codefile with hex assembly
|
||||||
if hexcode, err = ioutil.ReadFile(ctx.GlobalString(CodeFileFlag.Name)); err != nil {
|
if hexcode, err = ioutil.ReadFile(codeFileFlag); err != nil {
|
||||||
fmt.Printf("Could not load code from file: %v\n", err)
|
fmt.Printf("Could not load code from file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
code = common.Hex2Bytes(string(bytes.TrimRight(hexcode, "\n")))
|
} else {
|
||||||
|
hexcode = []byte(codeFlag)
|
||||||
} else if ctx.GlobalString(CodeFlag.Name) != "" {
|
}
|
||||||
code = common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name))
|
if len(hexcode)%2 != 0 {
|
||||||
|
fmt.Printf("Invalid input length for hex data (%d)\n", len(hexcode))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
code = common.FromHex(string(hexcode))
|
||||||
} else if fn := ctx.Args().First(); len(fn) > 0 {
|
} else if fn := ctx.Args().First(); len(fn) > 0 {
|
||||||
// EASM-file to compile
|
// EASM-file to compile
|
||||||
src, err := ioutil.ReadFile(fn)
|
src, err := ioutil.ReadFile(fn)
|
||||||
@ -155,7 +162,6 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
code = common.Hex2Bytes(bin)
|
code = common.Hex2Bytes(bin)
|
||||||
}
|
}
|
||||||
|
|
||||||
initialGas := ctx.GlobalUint64(GasFlag.Name)
|
initialGas := ctx.GlobalUint64(GasFlag.Name)
|
||||||
if genesisConfig.GasLimit != 0 {
|
if genesisConfig.GasLimit != 0 {
|
||||||
initialGas = genesisConfig.GasLimit
|
initialGas = genesisConfig.GasLimit
|
||||||
|
Loading…
Reference in New Issue
Block a user