aboutsummaryrefslogtreecommitdiffstats
path: root/ethpipe
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-05 17:10:24 +0800
committerobscuren <geffobscura@gmail.com>2014-08-05 17:10:24 +0800
commit4f0bda403ea332eeb477f8e56457423628772b19 (patch)
treea601453b364160a3af94ee324e198fcb304fc5a4 /ethpipe
parentc215bbadf13ec70e4d1b65e67d4ff4568d644542 (diff)
downloadgo-tangerine-4f0bda403ea332eeb477f8e56457423628772b19.tar
go-tangerine-4f0bda403ea332eeb477f8e56457423628772b19.tar.gz
go-tangerine-4f0bda403ea332eeb477f8e56457423628772b19.tar.bz2
go-tangerine-4f0bda403ea332eeb477f8e56457423628772b19.tar.lz
go-tangerine-4f0bda403ea332eeb477f8e56457423628772b19.tar.xz
go-tangerine-4f0bda403ea332eeb477f8e56457423628772b19.tar.zst
go-tangerine-4f0bda403ea332eeb477f8e56457423628772b19.zip
Added vm options for object execution
Diffstat (limited to 'ethpipe')
-rw-r--r--ethpipe/config.go26
-rw-r--r--ethpipe/object.go26
-rw-r--r--ethpipe/pipe.go33
-rw-r--r--ethpipe/world.go12
4 files changed, 58 insertions, 39 deletions
diff --git a/ethpipe/config.go b/ethpipe/config.go
index 764f5596f..81d36d514 100644
--- a/ethpipe/config.go
+++ b/ethpipe/config.go
@@ -1,33 +1,14 @@
package ethpipe
-import (
- "github.com/ethereum/eth-go/ethstate"
- "github.com/ethereum/eth-go/ethutil"
-)
+import "github.com/ethereum/eth-go/ethutil"
var cnfCtr = ethutil.Hex2Bytes("661005d2720d855f1d9976f88bb10c1a3398c77f")
-type object struct {
- *ethstate.StateObject
-}
-
-func (self object) StorageString(str string) *ethutil.Value {
- if ethutil.IsHex(str) {
- return self.Storage(ethutil.Hex2Bytes(str[2:]))
- } else {
- return self.Storage(ethutil.RightPadBytes([]byte(str), 32))
- }
-}
-
-func (self object) Storage(addr []byte) *ethutil.Value {
- return self.StateObject.GetStorage(ethutil.BigD(addr))
-}
-
type config struct {
pipe *Pipe
}
-func (self *config) Get(name string) object {
+func (self *config) Get(name string) *object {
configCtrl := self.pipe.World().safeGet(cnfCtr)
var addr []byte
@@ -39,7 +20,8 @@ func (self *config) Get(name string) object {
}
objectAddr := configCtrl.GetStorage(ethutil.BigD(addr))
- return object{self.pipe.World().safeGet(objectAddr.Bytes())}
+
+ return &object{self.pipe.World().safeGet(objectAddr.Bytes())}
}
func (self *config) Exist() bool {
diff --git a/ethpipe/object.go b/ethpipe/object.go
new file mode 100644
index 000000000..ebfb5b904
--- /dev/null
+++ b/ethpipe/object.go
@@ -0,0 +1,26 @@
+package ethpipe
+
+import (
+ "github.com/ethereum/eth-go/ethstate"
+ "github.com/ethereum/eth-go/ethutil"
+)
+
+type object struct {
+ *ethstate.StateObject
+}
+
+func (self *object) StorageString(str string) *ethutil.Value {
+ if ethutil.IsHex(str) {
+ return self.Storage(ethutil.Hex2Bytes(str[2:]))
+ } else {
+ return self.Storage(ethutil.RightPadBytes([]byte(str), 32))
+ }
+}
+
+func (self *object) StorageValue(addr *ethutil.Value) *ethutil.Value {
+ return self.Storage(addr.Bytes())
+}
+
+func (self *object) Storage(addr []byte) *ethutil.Value {
+ return self.StateObject.GetStorage(ethutil.BigD(addr))
+}
diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go
index ca0a3416c..876a953aa 100644
--- a/ethpipe/pipe.go
+++ b/ethpipe/pipe.go
@@ -13,11 +13,17 @@ import (
var logger = ethlog.NewLogger("PIPE")
+type VmVars struct {
+ State *ethstate.State
+}
+
type Pipe struct {
obj ethchain.EthManager
stateManager *ethchain.StateManager
blockChain *ethchain.BlockChain
world *world
+
+ Vm VmVars
}
func New(obj ethchain.EthManager) *Pipe {
@@ -40,19 +46,22 @@ func (self *Pipe) Nonce(addr []byte) uint64 {
}
func (self *Pipe) Execute(addr []byte, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
- return self.ExecuteObject(self.World().safeGet(addr), data, value, gas, price)
+ return self.ExecuteObject(&object{self.World().safeGet(addr)}, data, value, gas, price)
}
-func (self *Pipe) ExecuteObject(object *ethstate.StateObject, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
+func (self *Pipe) ExecuteObject(object *object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
var (
- initiator = ethstate.NewStateObject([]byte{0})
- state = self.World().State().Copy()
- block = self.blockChain.CurrentBlock
+ initiator = ethstate.NewStateObject([]byte{0})
+ block = self.blockChain.CurrentBlock
+ stateObject = object.StateObject
)
+ if self.Vm.State == nil {
+ self.Vm.State = self.World().State().Copy()
+ }
- vm := ethvm.New(NewEnv(state, block, value.BigInt(), initiator.Address()))
+ vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()))
- closure := ethvm.NewClosure(initiator, object, object.Code, gas.BigInt(), price.BigInt())
+ closure := ethvm.NewClosure(initiator, stateObject, object.Code, gas.BigInt(), price.BigInt())
ret, _, err := closure.Call(vm, data)
return ret, err
@@ -79,7 +88,7 @@ func (self *Pipe) Exists(addr []byte) bool {
return self.World().Get(addr) != nil
}
-func (self *Pipe) TransactString(key *ethcrypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) error {
+func (self *Pipe) TransactString(key *ethcrypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) ([]byte, error) {
// Check if an address is stored by this address
var hash []byte
addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes()
@@ -94,7 +103,7 @@ func (self *Pipe) TransactString(key *ethcrypto.KeyPair, rec string, value, gas,
return self.Transact(key, hash, value, gas, price, data)
}
-func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price *ethutil.Value, data []byte) error {
+func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price *ethutil.Value, data []byte) ([]byte, error) {
var hash []byte
var contractCreation bool
if rec == nil {
@@ -106,7 +115,7 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price
if contractCreation {
script, err := ethutil.Compile(string(data), false)
if err != nil {
- return err
+ return nil, err
}
tx = ethchain.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), script)
@@ -133,7 +142,9 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price
if contractCreation {
logger.Infof("Contract addr %x", tx.CreationAddress())
+
+ return tx.CreationAddress(), nil
}
- return nil
+ return tx.Hash(), nil
}
diff --git a/ethpipe/world.go b/ethpipe/world.go
index 42e19fe00..25e2a1952 100644
--- a/ethpipe/world.go
+++ b/ethpipe/world.go
@@ -26,17 +26,17 @@ func (self *world) State() *ethstate.State {
return self.pipe.stateManager.CurrentState()
}
-func (self *world) Get(addr []byte) *ethstate.StateObject {
- return self.State().GetStateObject(addr)
+func (self *world) Get(addr []byte) *object {
+ return &object{self.State().GetStateObject(addr)}
}
func (self *world) safeGet(addr []byte) *ethstate.StateObject {
- object := self.Get(addr)
- if object != nil {
- return object
+ object := self.State().GetStateObject(addr)
+ if object == nil {
+ object = ethstate.NewStateObject(addr)
}
- return ethstate.NewStateObject(addr)
+ return object
}
func (self *world) Coinbase() *ethstate.StateObject {