aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-06-15 16:35:34 +0800
committerGitHub <noreply@github.com>2016-06-15 16:35:34 +0800
commit79ada05756a3abe299bc582bdb53644995197c57 (patch)
treed89fcd37aede33441e95389cc5a6ad3d74f2ec3a
parentc48271958f0020bc1a284fbb8b73b4bffa8b8dd9 (diff)
parente5165aeb277b1f1ae8d5bf60c22716ccd874a8e6 (diff)
downloaddexon-79ada05756a3abe299bc582bdb53644995197c57.tar
dexon-79ada05756a3abe299bc582bdb53644995197c57.tar.gz
dexon-79ada05756a3abe299bc582bdb53644995197c57.tar.bz2
dexon-79ada05756a3abe299bc582bdb53644995197c57.tar.lz
dexon-79ada05756a3abe299bc582bdb53644995197c57.tar.xz
dexon-79ada05756a3abe299bc582bdb53644995197c57.tar.zst
dexon-79ada05756a3abe299bc582bdb53644995197c57.zip
Merge pull request #2693 from obscuren/evm-bin-create
cmd/evm: added --create flag indicating the exec code is to be created
-rw-r--r--cmd/evm/main.go45
1 files changed, 34 insertions, 11 deletions
diff --git a/cmd/evm/main.go b/cmd/evm/main.go
index e7b266d4e..aa48f6ede 100644
--- a/cmd/evm/main.go
+++ b/cmd/evm/main.go
@@ -84,11 +84,16 @@ var (
Name: "verbosity",
Usage: "sets the verbosity level",
}
+ CreateFlag = cli.BoolFlag{
+ Name: "create",
+ Usage: "indicates the action should be create rather than call",
+ }
)
func init() {
app = utils.NewApp("0.2", "the evm command line interface")
app.Flags = []cli.Flag{
+ CreateFlag,
DebugFlag,
VerbosityFlag,
ForceJitFlag,
@@ -111,8 +116,6 @@ func run(ctx *cli.Context) error {
db, _ := ethdb.NewMemDatabase()
statedb, _ := state.New(common.Hash{}, db)
sender := statedb.CreateAccount(common.StringToAddress("sender"))
- receiver := statedb.CreateAccount(common.StringToAddress("receiver"))
- receiver.SetCode(common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)))
vmenv := NewEnv(statedb, common.StringToAddress("evmuser"), common.Big(ctx.GlobalString(ValueFlag.Name)), vm.Config{
Debug: ctx.GlobalBool(DebugFlag.Name),
@@ -121,17 +124,37 @@ func run(ctx *cli.Context) error {
})
tstart := time.Now()
- ret, e := vmenv.Call(
- sender,
- receiver.Address(),
- common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)),
- common.Big(ctx.GlobalString(GasFlag.Name)),
- common.Big(ctx.GlobalString(PriceFlag.Name)),
- common.Big(ctx.GlobalString(ValueFlag.Name)),
+
+ var (
+ ret []byte
+ err error
)
+
+ if ctx.GlobalBool(CreateFlag.Name) {
+ input := append(common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)), common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...)
+ ret, _, err = vmenv.Create(
+ sender,
+ input,
+ common.Big(ctx.GlobalString(GasFlag.Name)),
+ common.Big(ctx.GlobalString(PriceFlag.Name)),
+ common.Big(ctx.GlobalString(ValueFlag.Name)),
+ )
+ } else {
+ receiver := statedb.CreateAccount(common.StringToAddress("receiver"))
+ receiver.SetCode(common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)))
+ ret, err = vmenv.Call(
+ sender,
+ receiver.Address(),
+ common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)),
+ common.Big(ctx.GlobalString(GasFlag.Name)),
+ common.Big(ctx.GlobalString(PriceFlag.Name)),
+ common.Big(ctx.GlobalString(ValueFlag.Name)),
+ )
+ }
vmdone := time.Since(tstart)
if ctx.GlobalBool(DumpFlag.Name) {
+ statedb.Commit()
fmt.Println(string(statedb.Dump()))
}
vm.StdErrFormat(vmenv.StructLogs())
@@ -150,8 +173,8 @@ num gc: %d
}
fmt.Printf("OUT: 0x%x", ret)
- if e != nil {
- fmt.Printf(" error: %v", e)
+ if err != nil {
+ fmt.Printf(" error: %v", err)
}
fmt.Println()
return nil