aboutsummaryrefslogtreecommitdiffstats
path: root/core/execution.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-17 18:19:23 +0800
committerobscuren <geffobscura@gmail.com>2015-03-17 18:19:23 +0800
commit515d9432fcef8c574627049d437d6898b56c2829 (patch)
tree40322c532a38b8f563d452bd75dab69729e55d92 /core/execution.go
parent8ce6a3647821706cf5e9bb1a9dc13f23c84f6585 (diff)
downloaddexon-515d9432fcef8c574627049d437d6898b56c2829.tar.gz
dexon-515d9432fcef8c574627049d437d6898b56c2829.tar.zst
dexon-515d9432fcef8c574627049d437d6898b56c2829.zip
converted vm
Diffstat (limited to 'core/execution.go')
-rw-r--r--core/execution.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/core/execution.go b/core/execution.go
index be45eeeb4..4f15fb42a 100644
--- a/core/execution.go
+++ b/core/execution.go
@@ -4,6 +4,7 @@ import (
"math/big"
"time"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm"
@@ -11,26 +12,23 @@ import (
type Execution struct {
env vm.Environment
- address, input []byte
+ address *common.Address
+ input []byte
Gas, price, value *big.Int
}
-func NewExecution(env vm.Environment, address, input []byte, gas, gasPrice, value *big.Int) *Execution {
+func NewExecution(env vm.Environment, address *common.Address, input []byte, gas, gasPrice, value *big.Int) *Execution {
return &Execution{env: env, address: address, input: input, Gas: gas, price: gasPrice, value: value}
}
-func (self *Execution) Addr() []byte {
- return self.address
-}
-
-func (self *Execution) Call(codeAddr []byte, caller vm.ContextRef) ([]byte, error) {
+func (self *Execution) Call(codeAddr common.Address, caller vm.ContextRef) ([]byte, error) {
// Retrieve the executing code
code := self.env.State().GetCode(codeAddr)
- return self.exec(code, codeAddr, caller)
+ return self.exec(&codeAddr, code, caller)
}
-func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret []byte, err error) {
+func (self *Execution) exec(contextAddr *common.Address, code []byte, caller vm.ContextRef) (ret []byte, err error) {
env := self.env
evm := vm.NewVm(env)
if env.Depth() == vm.MaxCallDepth {
@@ -40,14 +38,15 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret
}
vsnapshot := env.State().Copy()
- if len(self.address) == 0 {
+ if self.address == nil {
// Generate a new address
nonce := env.State().GetNonce(caller.Address())
- self.address = crypto.CreateAddress(caller.Address(), nonce)
+ addr := crypto.CreateAddress(caller.Address(), nonce)
+ self.address = &addr
env.State().SetNonce(caller.Address(), nonce+1)
}
- from, to := env.State().GetStateObject(caller.Address()), env.State().GetOrNewStateObject(self.address)
+ from, to := env.State().GetStateObject(caller.Address()), env.State().GetOrNewStateObject(*self.address)
err = env.Transfer(from, to, self.value)
if err != nil {
env.State().Set(vsnapshot)
@@ -73,8 +72,8 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret
}
func (self *Execution) Create(caller vm.ContextRef) (ret []byte, err error, account *state.StateObject) {
- ret, err = self.exec(self.input, nil, caller)
- account = self.env.State().GetStateObject(self.address)
+ ret, err = self.exec(nil, self.input, caller)
+ account = self.env.State().GetStateObject(*self.address)
return
}