diff options
author | Nick Johnson <arachnid@notdot.net> | 2016-10-29 17:07:38 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-10-29 17:07:38 +0800 |
commit | 00665a0b72ed93692daec21bbd79931828653228 (patch) | |
tree | 171f0be73b6a80e86cc7e8e9669006866f2f228b /cmd/evm | |
parent | b59c8399fbe42390a3d41e945d03b1f21c1a9b8d (diff) | |
download | go-tangerine-00665a0b72ed93692daec21bbd79931828653228.tar.gz go-tangerine-00665a0b72ed93692daec21bbd79931828653228.tar.zst go-tangerine-00665a0b72ed93692daec21bbd79931828653228.zip |
cmd/evm: Allow stdin and files as sources of bytecode (#3172)
* cmd/evm: Allow stdin and files as sources of bytecode
* cmd/evm: Print and exit instead of panicing
* cmd/evm: fix compile and vet errors
Diffstat (limited to 'cmd/evm')
-rw-r--r-- | cmd/evm/main.go | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 9ca761b7b..704469432 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -19,6 +19,7 @@ package main import ( "fmt" + "io/ioutil" "math/big" "os" "runtime" @@ -58,6 +59,10 @@ var ( Name: "code", Usage: "EVM code", } + CodeFileFlag = cli.StringFlag{ + Name: "codefile", + Usage: "file containing EVM code", + } GasFlag = cli.StringFlag{ Name: "gas", Usage: "gas limit for the evm", @@ -104,6 +109,7 @@ func init() { DisableJitFlag, SysStatFlag, CodeFlag, + CodeFileFlag, GasFlag, PriceFlag, ValueFlag, @@ -133,12 +139,35 @@ func run(ctx *cli.Context) error { tstart := time.Now() var ( - ret []byte - err error + code []byte + ret []byte + err error ) + if ctx.GlobalString(CodeFlag.Name) != "" { + code = common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)) + } else { + var hexcode []byte + if ctx.GlobalString(CodeFileFlag.Name) != "" { + var err error + hexcode, err = ioutil.ReadFile(ctx.GlobalString(CodeFileFlag.Name)) + if err != nil { + fmt.Printf("Could not load code from file: %v\n", err) + os.Exit(1) + } + } else { + var err error + hexcode, err = ioutil.ReadAll(os.Stdin) + if err != nil { + fmt.Printf("Could not load code from stdin: %v\n", err) + os.Exit(1) + } + } + code = common.Hex2Bytes(string(hexcode[:])) + } + if ctx.GlobalBool(CreateFlag.Name) { - input := append(common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)), common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...) + input := append(code, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...) ret, _, err = vmenv.Create( sender, input, @@ -149,7 +178,6 @@ func run(ctx *cli.Context) error { } else { receiver := statedb.CreateAccount(common.StringToAddress("receiver")) - code := common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)) receiver.SetCode(crypto.Keccak256Hash(code), code) ret, err = vmenv.Call( sender, |