1717package main
1818
1919import (
20- "bytes"
2120 "encoding/json"
2221 "fmt"
2322 "io/ioutil"
@@ -121,28 +120,36 @@ func runCmd(ctx *cli.Context) error {
121120 ret []byte
122121 err error
123122 )
123+ codeFileFlag := ctx .GlobalString (CodeFileFlag .Name )
124+ codeFlag := ctx .GlobalString (CodeFlag .Name )
125+
124126 // The '--code' or '--codefile' flag overrides code in state
125- if ctx . GlobalString ( CodeFileFlag . Name ) != "" {
127+ if codeFileFlag != "" || codeFlag != "" {
126128 var hexcode []byte
127- var err error
128- // If - is specified, it means that code comes from stdin
129- if ctx .GlobalString (CodeFileFlag .Name ) == "-" {
130- //Try reading from stdin
131- if hexcode , err = ioutil .ReadAll (os .Stdin ); err != nil {
132- fmt .Printf ("Could not load code from stdin: %v\n " , err )
133- os .Exit (1 )
129+ if codeFileFlag != "" {
130+ var err error
131+ // If - is specified, it means that code comes from stdin
132+ if codeFileFlag == "-" {
133+ //Try reading from stdin
134+ if hexcode , err = ioutil .ReadAll (os .Stdin ); err != nil {
135+ fmt .Printf ("Could not load code from stdin: %v\n " , err )
136+ os .Exit (1 )
137+ }
138+ } else {
139+ // Codefile with hex assembly
140+ if hexcode , err = ioutil .ReadFile (codeFileFlag ); err != nil {
141+ fmt .Printf ("Could not load code from file: %v\n " , err )
142+ os .Exit (1 )
143+ }
134144 }
135145 } else {
136- // Codefile with hex assembly
137- if hexcode , err = ioutil .ReadFile (ctx .GlobalString (CodeFileFlag .Name )); err != nil {
138- fmt .Printf ("Could not load code from file: %v\n " , err )
139- os .Exit (1 )
140- }
146+ hexcode = []byte (codeFlag )
141147 }
142- code = common .Hex2Bytes (string (bytes .TrimRight (hexcode , "\n " )))
143-
144- } else if ctx .GlobalString (CodeFlag .Name ) != "" {
145- code = common .Hex2Bytes (ctx .GlobalString (CodeFlag .Name ))
148+ if len (hexcode )% 2 != 0 {
149+ fmt .Printf ("Invalid input length for hex data (%d)\n " , len (hexcode ))
150+ os .Exit (1 )
151+ }
152+ code = common .FromHex (string (hexcode ))
146153 } else if fn := ctx .Args ().First (); len (fn ) > 0 {
147154 // EASM-file to compile
148155 src , err := ioutil .ReadFile (fn )
@@ -155,7 +162,6 @@ func runCmd(ctx *cli.Context) error {
155162 }
156163 code = common .Hex2Bytes (bin )
157164 }
158-
159165 initialGas := ctx .GlobalUint64 (GasFlag .Name )
160166 if genesisConfig .GasLimit != 0 {
161167 initialGas = genesisConfig .GasLimit
0 commit comments