From 342cc122b43f01301d0188de1e333c32ed64ae8c Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 4 Aug 2014 16:25:53 +0200 Subject: Added general Pipe API --- ethpipe/config.go | 47 ++++++++++++++++++ ethpipe/pipe.go | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ ethpipe/pipe_test.go | 57 ++++++++++++++++++++++ ethpipe/vm_env.go | 33 +++++++++++++ ethpipe/world.go | 60 +++++++++++++++++++++++ 5 files changed, 332 insertions(+) create mode 100644 ethpipe/config.go create mode 100644 ethpipe/pipe.go create mode 100644 ethpipe/pipe_test.go create mode 100644 ethpipe/vm_env.go create mode 100644 ethpipe/world.go (limited to 'ethpipe') diff --git a/ethpipe/config.go b/ethpipe/config.go new file mode 100644 index 000000000..764f5596f --- /dev/null +++ b/ethpipe/config.go @@ -0,0 +1,47 @@ +package ethpipe + +import ( + "github.com/ethereum/eth-go/ethstate" + "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 { + configCtrl := self.pipe.World().safeGet(cnfCtr) + var addr []byte + + switch name { + case "NameReg": + addr = []byte{0} + default: + addr = ethutil.RightPadBytes([]byte(name), 32) + } + + objectAddr := configCtrl.GetStorage(ethutil.BigD(addr)) + return object{self.pipe.World().safeGet(objectAddr.Bytes())} +} + +func (self *config) Exist() bool { + return self.pipe.World().Get(cnfCtr) != nil +} diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go new file mode 100644 index 000000000..710fc4e7c --- /dev/null +++ b/ethpipe/pipe.go @@ -0,0 +1,135 @@ +package ethpipe + +import ( + "strings" + + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/ethlog" + "github.com/ethereum/eth-go/ethstate" + "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/ethvm" +) + +var logger = ethlog.NewLogger("PIPE") + +type Pipe struct { + obj ethchain.EthManager + stateManager *ethchain.StateManager + blockChain *ethchain.BlockChain + world *world +} + +func New(obj ethchain.EthManager) *Pipe { + pipe := &Pipe{ + obj: obj, + stateManager: obj.StateManager(), + blockChain: obj.BlockChain(), + } + pipe.world = NewWorld(pipe) + + return pipe +} + +func (self *Pipe) Balance(addr []byte) *ethutil.Value { + return ethutil.NewValue(self.World().safeGet(addr).Balance) +} + +func (self *Pipe) Nonce(addr []byte) uint64 { + return self.World().safeGet(addr).Nonce +} + +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) +} + +func (self *Pipe) ExecuteObject(object *ethstate.StateObject, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { + var ( + initiator = ethstate.NewStateObject([]byte{0}) + state = self.World().State().Copy() + block = self.blockChain.CurrentBlock + ) + + vm := ethvm.New(NewEnv(state, block, value.BigInt(), initiator.Address())) + + closure := ethvm.NewClosure(initiator, object, object.Code, gas.BigInt(), price.BigInt()) + ret, _, err := closure.Call(vm, data) + + return ret, err +} + +func (self *Pipe) Block(hash []byte) *ethchain.Block { + return self.blockChain.GetBlock(hash) +} + +func (self *Pipe) Storage(addr, storageAddr []byte) *ethutil.Value { + return self.World().safeGet(addr).GetStorage(ethutil.BigD(storageAddr)) +} + +func (self *Pipe) ToAddress(priv []byte) []byte { + pair, err := ethcrypto.NewKeyPairFromSec(priv) + if err != nil { + return nil + } + + return pair.Address() +} + +func (self *Pipe) TransactString(key *ethcrypto.KeyPair, rec string, value, gas, price *ethutil.Value, data []byte) error { + // Check if an address is stored by this address + var hash []byte + addr := self.World().Config().Get("NameReg").StorageString(rec).Bytes() + if len(addr) > 0 { + hash = addr + } else if ethutil.IsHex(rec) { + hash = ethutil.Hex2Bytes(rec[2:]) + } else { + hash = ethutil.Hex2Bytes(rec) + } + + 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 { + var hash []byte + var contractCreation bool + if rec == nil { + contractCreation = true + } + + var tx *ethchain.Transaction + // Compile and assemble the given data + if contractCreation { + script, err := ethutil.Compile(string(data), false) + if err != nil { + return err + } + + tx = ethchain.NewContractCreationTx(value.BigInt(), gas.BigInt(), price.BigInt(), script) + } else { + data := ethutil.StringToByteFunc(string(data), func(s string) (ret []byte) { + slice := strings.Split(s, "\n") + for _, dataItem := range slice { + d := ethutil.FormatData(dataItem) + ret = append(ret, d...) + } + return + }) + + tx = ethchain.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) + } + + acc := self.stateManager.TransState().GetOrNewStateObject(key.Address()) + tx.Nonce = acc.Nonce + acc.Nonce += 1 + self.stateManager.TransState().UpdateStateObject(acc) + + tx.Sign(key.PrivateKey) + self.obj.TxPool().QueueTransaction(tx) + + if contractCreation { + logger.Infof("Contract addr %x", tx.CreationAddress()) + } + + return nil +} diff --git a/ethpipe/pipe_test.go b/ethpipe/pipe_test.go new file mode 100644 index 000000000..d0b8ef948 --- /dev/null +++ b/ethpipe/pipe_test.go @@ -0,0 +1,57 @@ +package ethpipe + +import ( + "testing" + + "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/ethstate" + "github.com/ethereum/eth-go/ethutil" +) + +func Val(v interface{}) *ethutil.Value { + return ethutil.NewValue(v) +} + +func TestNew(t *testing.T) { + pipe := New(nil) + + var addr, privy, recp, data []byte + var object *ethstate.StateObject + var key *ethcrypto.KeyPair + + world := pipe.World() + world.Get(addr) + world.Coinbase() + world.IsMining() + world.IsListening() + world.State() + peers := world.Peers() + peers.Len() + + // Shortcut functions + pipe.Balance(addr) + pipe.Nonce(addr) + pipe.Block(addr) + pipe.Storage(addr, addr) + pipe.ToAddress(privy) + // Doesn't change state + pipe.Execute(addr, nil, Val(0), Val(1000000), Val(10)) + // Doesn't change state + pipe.ExecuteObject(object, nil, Val(0), Val(1000000), Val(10)) + + conf := world.Config() + namereg := conf.Get("NameReg") + namereg.Storage(addr) + + var err error + // Transact + err = pipe.Transact(key, recp, ethutil.NewValue(0), ethutil.NewValue(0), ethutil.NewValue(0), nil) + if err != nil { + t.Error(err) + } + // Create + err = pipe.Transact(key, nil, ethutil.NewValue(0), ethutil.NewValue(0), ethutil.NewValue(0), data) + if err != nil { + t.Error(err) + } +} diff --git a/ethpipe/vm_env.go b/ethpipe/vm_env.go new file mode 100644 index 000000000..c06a2a763 --- /dev/null +++ b/ethpipe/vm_env.go @@ -0,0 +1,33 @@ +package ethpipe + +import ( + "math/big" + + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethstate" +) + +type VMEnv struct { + state *ethstate.State + block *ethchain.Block + value *big.Int + sender []byte +} + +func NewEnv(state *ethstate.State, block *ethchain.Block, value *big.Int, sender []byte) *VMEnv { + return &VMEnv{ + state: state, + block: block, + value: value, + sender: sender, + } +} + +func (self *VMEnv) Origin() []byte { return self.sender } +func (self *VMEnv) BlockNumber() *big.Int { return self.block.Number } +func (self *VMEnv) PrevHash() []byte { return self.block.PrevHash } +func (self *VMEnv) Coinbase() []byte { return self.block.Coinbase } +func (self *VMEnv) Time() int64 { return self.block.Time } +func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty } +func (self *VMEnv) Value() *big.Int { return self.value } +func (self *VMEnv) State() *ethstate.State { return self.state } diff --git a/ethpipe/world.go b/ethpipe/world.go new file mode 100644 index 000000000..507391521 --- /dev/null +++ b/ethpipe/world.go @@ -0,0 +1,60 @@ +package ethpipe + +import ( + "container/list" + + "github.com/ethereum/eth-go/ethstate" +) + +type world struct { + pipe *Pipe + cfg *config +} + +func NewWorld(pipe *Pipe) *world { + world := &world{pipe, nil} + world.cfg = &config{pipe} + + return world +} + +func (self *Pipe) World() *world { + return self.world +} + +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) safeGet(addr []byte) *ethstate.StateObject { + object := self.Get(addr) + if object != nil { + return object + } + + return ethstate.NewStateObject(addr) +} + +func (self *world) Coinbase() *ethstate.StateObject { + return nil +} + +func (self *world) IsMining() bool { + return self.pipe.obj.IsMining() +} + +func (self *world) IsListening() bool { + return self.pipe.obj.IsListening() +} + +func (self *world) Peers() *list.List { + return self.obj.Peers() +} + +func (self *world) Config() *config { + return self.cfg +} -- cgit From 0f84b9c30d06a59f20a2d33ffd1281d5e6e2681a Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 4 Aug 2014 16:34:55 +0200 Subject: Added exist method --- ethpipe/pipe.go | 4 ++++ ethpipe/pipe_test.go | 1 + 2 files changed, 5 insertions(+) (limited to 'ethpipe') diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index 710fc4e7c..ca0a3416c 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -75,6 +75,10 @@ func (self *Pipe) ToAddress(priv []byte) []byte { return pair.Address() } +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 { // Check if an address is stored by this address var hash []byte diff --git a/ethpipe/pipe_test.go b/ethpipe/pipe_test.go index d0b8ef948..071213050 100644 --- a/ethpipe/pipe_test.go +++ b/ethpipe/pipe_test.go @@ -34,6 +34,7 @@ func TestNew(t *testing.T) { pipe.Block(addr) pipe.Storage(addr, addr) pipe.ToAddress(privy) + pipe.Exists(addr) // Doesn't change state pipe.Execute(addr, nil, Val(0), Val(1000000), Val(10)) // Doesn't change state -- cgit From c215bbadf13ec70e4d1b65e67d4ff4568d644542 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 5 Aug 2014 10:17:26 +0200 Subject: pipe --- ethpipe/world.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/world.go b/ethpipe/world.go index 507391521..42e19fe00 100644 --- a/ethpipe/world.go +++ b/ethpipe/world.go @@ -52,7 +52,7 @@ func (self *world) IsListening() bool { } func (self *world) Peers() *list.List { - return self.obj.Peers() + return self.pipe.obj.Peers() } func (self *world) Config() *config { -- cgit From 4f0bda403ea332eeb477f8e56457423628772b19 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 5 Aug 2014 11:10:24 +0200 Subject: Added vm options for object execution --- ethpipe/config.go | 26 ++++---------------------- ethpipe/object.go | 26 ++++++++++++++++++++++++++ ethpipe/pipe.go | 33 ++++++++++++++++++++++----------- ethpipe/world.go | 12 ++++++------ 4 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 ethpipe/object.go (limited to 'ethpipe') 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 { -- cgit From e71b198e3d8df1bd8b73bae9bc934b778a3115bf Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 5 Aug 2014 11:26:12 +0200 Subject: Renamed object to Object --- ethpipe/config.go | 4 ++-- ethpipe/object.go | 8 ++++---- ethpipe/pipe.go | 4 ++-- ethpipe/world.go | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/config.go b/ethpipe/config.go index 81d36d514..588fc8d97 100644 --- a/ethpipe/config.go +++ b/ethpipe/config.go @@ -8,7 +8,7 @@ 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 @@ -21,7 +21,7 @@ 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 index ebfb5b904..f0032992c 100644 --- a/ethpipe/object.go +++ b/ethpipe/object.go @@ -5,11 +5,11 @@ import ( "github.com/ethereum/eth-go/ethutil" ) -type object struct { +type Object struct { *ethstate.StateObject } -func (self *object) StorageString(str string) *ethutil.Value { +func (self *Object) StorageString(str string) *ethutil.Value { if ethutil.IsHex(str) { return self.Storage(ethutil.Hex2Bytes(str[2:])) } else { @@ -17,10 +17,10 @@ func (self *object) StorageString(str string) *ethutil.Value { } } -func (self *object) StorageValue(addr *ethutil.Value) *ethutil.Value { +func (self *Object) StorageValue(addr *ethutil.Value) *ethutil.Value { return self.Storage(addr.Bytes()) } -func (self *object) Storage(addr []byte) *ethutil.Value { +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 876a953aa..c00731b84 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -46,10 +46,10 @@ 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(&object{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 *object, 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}) block = self.blockChain.CurrentBlock diff --git a/ethpipe/world.go b/ethpipe/world.go index 25e2a1952..2a07f340c 100644 --- a/ethpipe/world.go +++ b/ethpipe/world.go @@ -26,8 +26,8 @@ func (self *world) State() *ethstate.State { return self.pipe.stateManager.CurrentState() } -func (self *world) Get(addr []byte) *object { - return &object{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 { -- cgit From 3c78e418fbe70cfb574302f00962cf7fac50f69e Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 5 Aug 2014 11:30:12 +0200 Subject: world => World --- ethpipe/pipe.go | 2 +- ethpipe/world.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index c00731b84..a9da66ab8 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -21,7 +21,7 @@ type Pipe struct { obj ethchain.EthManager stateManager *ethchain.StateManager blockChain *ethchain.BlockChain - world *world + world *World Vm VmVars } diff --git a/ethpipe/world.go b/ethpipe/world.go index 2a07f340c..2c6b0b4b9 100644 --- a/ethpipe/world.go +++ b/ethpipe/world.go @@ -6,31 +6,31 @@ import ( "github.com/ethereum/eth-go/ethstate" ) -type world struct { +type World struct { pipe *Pipe cfg *config } -func NewWorld(pipe *Pipe) *world { - world := &world{pipe, nil} +func NewWorld(pipe *Pipe) *World { + world := &World{pipe, nil} world.cfg = &config{pipe} return world } -func (self *Pipe) World() *world { +func (self *Pipe) World() *World { return self.world } -func (self *world) State() *ethstate.State { +func (self *World) State() *ethstate.State { return self.pipe.stateManager.CurrentState() } -func (self *world) Get(addr []byte) *Object { +func (self *World) Get(addr []byte) *Object { return &Object{self.State().GetStateObject(addr)} } -func (self *world) safeGet(addr []byte) *ethstate.StateObject { +func (self *World) safeGet(addr []byte) *ethstate.StateObject { object := self.State().GetStateObject(addr) if object == nil { object = ethstate.NewStateObject(addr) @@ -39,22 +39,22 @@ func (self *world) safeGet(addr []byte) *ethstate.StateObject { return object } -func (self *world) Coinbase() *ethstate.StateObject { +func (self *World) Coinbase() *ethstate.StateObject { return nil } -func (self *world) IsMining() bool { +func (self *World) IsMining() bool { return self.pipe.obj.IsMining() } -func (self *world) IsListening() bool { +func (self *World) IsListening() bool { return self.pipe.obj.IsListening() } -func (self *world) Peers() *list.List { +func (self *World) Peers() *list.List { return self.pipe.obj.Peers() } -func (self *world) Config() *config { +func (self *World) Config() *config { return self.cfg } -- cgit From 4edf7cfb0543555921a79f572c749615c4997ea7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 5 Aug 2014 11:31:39 +0200 Subject: config => Config --- ethpipe/config.go | 6 +++--- ethpipe/world.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/config.go b/ethpipe/config.go index 588fc8d97..5e57416d7 100644 --- a/ethpipe/config.go +++ b/ethpipe/config.go @@ -4,11 +4,11 @@ import "github.com/ethereum/eth-go/ethutil" var cnfCtr = ethutil.Hex2Bytes("661005d2720d855f1d9976f88bb10c1a3398c77f") -type config struct { +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 @@ -24,6 +24,6 @@ func (self *config) Get(name string) *Object { return &Object{self.pipe.World().safeGet(objectAddr.Bytes())} } -func (self *config) Exist() bool { +func (self *Config) Exist() bool { return self.pipe.World().Get(cnfCtr) != nil } diff --git a/ethpipe/world.go b/ethpipe/world.go index 2c6b0b4b9..72e116d09 100644 --- a/ethpipe/world.go +++ b/ethpipe/world.go @@ -8,12 +8,12 @@ import ( type World struct { pipe *Pipe - cfg *config + cfg *Config } func NewWorld(pipe *Pipe) *World { world := &World{pipe, nil} - world.cfg = &config{pipe} + world.cfg = &Config{pipe} return world } @@ -55,6 +55,6 @@ func (self *World) Peers() *list.List { return self.pipe.obj.Peers() } -func (self *World) Config() *config { +func (self *World) Config() *Config { return self.cfg } -- cgit From 7272577fe651a20618cf428475e2e57976c9599d Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 7 Aug 2014 15:11:54 +0200 Subject: Added dns lookup --- ethpipe/config.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ethpipe') diff --git a/ethpipe/config.go b/ethpipe/config.go index 5e57416d7..66708b26e 100644 --- a/ethpipe/config.go +++ b/ethpipe/config.go @@ -15,6 +15,11 @@ func (self *Config) Get(name string) *Object { switch name { case "NameReg": addr = []byte{0} + case "DomainReg": + objectAddr := configCtrl.GetStorage(ethutil.BigD([]byte{0})) + domainAddr := (&Object{self.pipe.World().safeGet(objectAddr.Bytes())}).StorageString("DomainReg").Bytes() + + return &Object{self.pipe.World().safeGet(domainAddr)} default: addr = ethutil.RightPadBytes([]byte(name), 32) } -- cgit From d6b0ab3028ba8d7a565d35ab7b8054ee921ba683 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 7 Aug 2014 15:26:07 +0200 Subject: Changed to DnsReg --- ethpipe/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/config.go b/ethpipe/config.go index 66708b26e..1e246c7b4 100644 --- a/ethpipe/config.go +++ b/ethpipe/config.go @@ -15,9 +15,9 @@ func (self *Config) Get(name string) *Object { switch name { case "NameReg": addr = []byte{0} - case "DomainReg": + case "DnsReg": objectAddr := configCtrl.GetStorage(ethutil.BigD([]byte{0})) - domainAddr := (&Object{self.pipe.World().safeGet(objectAddr.Bytes())}).StorageString("DomainReg").Bytes() + domainAddr := (&Object{self.pipe.World().safeGet(objectAddr.Bytes())}).StorageString("DnsReg").Bytes() return &Object{self.pipe.World().safeGet(domainAddr)} default: -- cgit From c51db4c940a5ea679aee580a673a4ccdd2421b9a Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 8 Aug 2014 14:36:59 +0100 Subject: Fixed stack issue --- ethpipe/config.go | 1 - 1 file changed, 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/config.go b/ethpipe/config.go index 1e246c7b4..6c24df640 100644 --- a/ethpipe/config.go +++ b/ethpipe/config.go @@ -18,7 +18,6 @@ func (self *Config) Get(name string) *Object { case "DnsReg": objectAddr := configCtrl.GetStorage(ethutil.BigD([]byte{0})) domainAddr := (&Object{self.pipe.World().safeGet(objectAddr.Bytes())}).StorageString("DnsReg").Bytes() - return &Object{self.pipe.World().safeGet(domainAddr)} default: addr = ethutil.RightPadBytes([]byte(name), 32) -- cgit From a760ce05b948e89bc564af20599dcf95698ac0eb Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 11 Aug 2014 16:23:38 +0200 Subject: Updated chain for filtering --- ethpipe/vm_env.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethpipe') diff --git a/ethpipe/vm_env.go b/ethpipe/vm_env.go index c06a2a763..822a9e5c7 100644 --- a/ethpipe/vm_env.go +++ b/ethpipe/vm_env.go @@ -29,5 +29,6 @@ func (self *VMEnv) PrevHash() []byte { return self.block.PrevHash } func (self *VMEnv) Coinbase() []byte { return self.block.Coinbase } func (self *VMEnv) Time() int64 { return self.block.Time } func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty } +func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) State() *ethstate.State { return self.state } -- cgit From d701b232304149f5e9035213d1710ab71cc4a01d Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 15 Aug 2014 13:05:13 +0200 Subject: Reworking the public js interface (pub) => (pipe) --- ethpipe/js_pipe.go | 168 +++++++++++++++++++++++++++++++++++++++++++++++++ ethpipe/js_types.go | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ethpipe/world.go | 4 ++ 3 files changed, 349 insertions(+) create mode 100644 ethpipe/js_pipe.go create mode 100644 ethpipe/js_types.go (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go new file mode 100644 index 000000000..a2d3fdf10 --- /dev/null +++ b/ethpipe/js_pipe.go @@ -0,0 +1,168 @@ +package ethpipe + +import ( + "encoding/json" + "sync/atomic" + + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/ethutil" +) + +type JSPipe struct { + *Pipe +} + +func NewJSPipe(eth ethchain.EthManager) *JSPipe { + return &JSPipe{New(eth)} +} + +func (self *JSPipe) GetBlockByHash(strHash string) *JSBlock { + hash := ethutil.Hex2Bytes(strHash) + block := self.obj.BlockChain().GetBlock(hash) + + return NewJSBlock(block) +} + +func (self *JSPipe) GetKey() *JSKey { + return NewJSKey(self.obj.KeyManager().KeyPair()) +} + +func (self *JSPipe) GetStateObject(addr string) *JSObject { + object := &Object{self.World().safeGet(ethutil.Hex2Bytes(addr))} + + return NewJSObject(object) +} + +func (self *JSPipe) GetPeerCount() int { + return self.obj.PeerCount() +} + +func (self *JSPipe) GetPeers() []JSPeer { + var peers []JSPeer + for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() { + p := peer.Value.(ethchain.Peer) + // we only want connected peers + if atomic.LoadInt32(p.Connected()) != 0 { + peers = append(peers, *NewJSPeer(p)) + } + } + + return peers +} + +func (self *JSPipe) GetIsMining() bool { + return self.obj.IsMining() +} + +func (self *JSPipe) GetIsListening() bool { + return self.obj.IsListening() +} + +func (self *JSPipe) GetCoinBase() string { + return ethutil.Bytes2Hex(self.obj.KeyManager().Address()) +} + +func (self *JSPipe) GetStorage(addr, storageAddr string) string { + return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)).Str() +} + +func (self *JSPipe) GetTxCountAt(address string) int { + return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce) +} + +func (self *JSPipe) IsContract(address string) bool { + return len(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) > 0 +} + +func (self *JSPipe) SecretToAddress(key string) string { + pair, err := ethcrypto.NewKeyPairFromSec(ethutil.Hex2Bytes(key)) + if err != nil { + return "" + } + + return ethutil.Bytes2Hex(pair.Address()) +} + +type KeyVal struct { + Key string `json:"key"` + Value string `json:"value"` +} + +func (self *JSPipe) GetEachStorage(addr string) string { + var values []KeyVal + object := self.World().SafeGet(ethutil.Hex2Bytes(addr)) + object.EachStorage(func(name string, value *ethutil.Value) { + value.Decode() + values = append(values, KeyVal{ethutil.Bytes2Hex([]byte(name)), ethutil.Bytes2Hex(value.Bytes())}) + }) + + valuesJson, err := json.Marshal(values) + if err != nil { + return "" + } + + return string(valuesJson) +} + +func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) { + var hash []byte + var contractCreation bool + if len(toStr) == 0 { + contractCreation = true + } else { + // Check if an address is stored by this address + addr := self.World().Config().Get("NameReg").StorageString(toStr).Bytes() + if len(addr) > 0 { + hash = addr + } else { + hash = ethutil.Hex2Bytes(toStr) + } + } + + var keyPair *ethcrypto.KeyPair + var err error + if ethutil.IsHex(key) { + keyPair, err = ethcrypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key[2:]))) + } else { + keyPair, err = ethcrypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key))) + } + + if err != nil { + return nil, err + } + + var ( + value = ethutil.Big(valueStr) + gas = ethutil.Big(gasStr) + gasPrice = ethutil.Big(gasPriceStr) + data []byte + tx *ethchain.Transaction + ) + + if ethutil.IsHex(codeStr) { + data = ethutil.Hex2Bytes(codeStr[2:]) + } else { + data = ethutil.Hex2Bytes(codeStr) + } + + if contractCreation { + tx = ethchain.NewContractCreationTx(value, gas, gasPrice, data) + } else { + tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, data) + } + + acc := self.obj.StateManager().TransState().GetOrNewStateObject(keyPair.Address()) + tx.Nonce = acc.Nonce + acc.Nonce += 1 + self.obj.StateManager().TransState().UpdateStateObject(acc) + + tx.Sign(keyPair.PrivateKey) + self.obj.TxPool().QueueTransaction(tx) + + if contractCreation { + logger.Infof("Contract addr %x", tx.CreationAddress()) + } + + return NewJSReciept(contractCreation, tx.CreationAddress(), tx.Hash(), keyPair.Address()), nil +} diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go new file mode 100644 index 000000000..e1743486b --- /dev/null +++ b/ethpipe/js_types.go @@ -0,0 +1,177 @@ +package ethpipe + +import ( + "encoding/json" + "strconv" + "strings" + + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/ethutil" +) + +// Block interface exposed to QML +type JSBlock struct { + ref *ethchain.Block + Number int `json:"number"` + Hash string `json:"hash"` + Transactions string `json:"transactions"` + Time int64 `json:"time"` + Coinbase string `json:"coinbase"` + Name string `json:"name"` + GasLimit string `json:"gasLimit"` + GasUsed string `json:"gasUsed"` +} + +// Creates a new QML Block from a chain block +func NewJSBlock(block *ethchain.Block) *JSBlock { + if block == nil { + return nil + } + + var ptxs []JSTransaction + for _, tx := range block.Transactions() { + ptxs = append(ptxs, *NewJSTx(tx)) + } + + txJson, err := json.Marshal(ptxs) + if err != nil { + return nil + } + + return &JSBlock{ref: block, Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} +} + +func (self *JSBlock) ToString() string { + if self.ref != nil { + return self.ref.String() + } + + return "" +} + +func (self *JSBlock) GetTransaction(hash string) *JSTransaction { + tx := self.ref.GetTransaction(ethutil.Hex2Bytes(hash)) + if tx == nil { + return nil + } + + return NewJSTx(tx) +} + +type JSTransaction struct { + ref *ethchain.Transaction + + Value string `json:"value"` + Gas string `json:"gas"` + GasPrice string `json:"gasPrice"` + Hash string `json:"hash"` + Address string `json:"address"` + Sender string `json:"sender"` + RawData string `json:"rawData"` + Data string `json:"data"` + Contract bool `json:"isContract"` + CreatesContract bool `json:"createsContract"` + Confirmations int `json:"confirmations"` +} + +func NewJSTx(tx *ethchain.Transaction) *JSTransaction { + hash := ethutil.Bytes2Hex(tx.Hash()) + receiver := ethutil.Bytes2Hex(tx.Recipient) + if receiver == "0000000000000000000000000000000000000000" { + receiver = ethutil.Bytes2Hex(tx.CreationAddress()) + } + sender := ethutil.Bytes2Hex(tx.Sender()) + createsContract := tx.CreatesContract() + + var data string + if tx.CreatesContract() { + data = strings.Join(ethchain.Disassemble(tx.Data), "\n") + } else { + data = ethutil.Bytes2Hex(tx.Data) + } + + return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: receiver, Contract: tx.CreatesContract(), Gas: tx.Gas.String(), GasPrice: tx.GasPrice.String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data)} +} + +func (self *JSTransaction) ToString() string { + return self.ref.String() +} + +type JSKey struct { + Address string `json:"address"` + PrivateKey string `json:"privateKey"` + PublicKey string `json:"publicKey"` +} + +func NewJSKey(key *ethcrypto.KeyPair) *JSKey { + return &JSKey{ethutil.Bytes2Hex(key.Address()), ethutil.Bytes2Hex(key.PrivateKey), ethutil.Bytes2Hex(key.PublicKey)} +} + +type JSObject struct { + *Object +} + +func NewJSObject(object *Object) *JSObject { + return &JSObject{object} +} + +type PReceipt struct { + CreatedContract bool `json:"createdContract"` + Address string `json:"address"` + Hash string `json:"hash"` + Sender string `json:"sender"` +} + +func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt { + return &PReceipt{ + contractCreation, + ethutil.Bytes2Hex(creationAddress), + ethutil.Bytes2Hex(hash), + ethutil.Bytes2Hex(address), + } +} + +// Peer interface exposed to QML + +type JSPeer struct { + ref *ethchain.Peer + Inbound bool `json:"isInbound"` + LastSend int64 `json:"lastSend"` + LastPong int64 `json:"lastPong"` + Ip string `json:"ip"` + Port int `json:"port"` + Version string `json:"version"` + LastResponse string `json:"lastResponse"` + Latency string `json:"latency"` +} + +func NewJSPeer(peer ethchain.Peer) *JSPeer { + if peer == nil { + return nil + } + + var ip []string + for _, i := range peer.Host() { + ip = append(ip, strconv.Itoa(int(i))) + } + ipAddress := strings.Join(ip, ".") + + return &JSPeer{ref: &peer, Inbound: peer.Inbound(), LastSend: peer.LastSend().Unix(), LastPong: peer.LastPong(), Version: peer.Version(), Ip: ipAddress, Port: int(peer.Port()), Latency: peer.PingTime()} +} + +type JSReceipt struct { + CreatedContract bool `json:"createdContract"` + Address string `json:"address"` + Hash string `json:"hash"` + Sender string `json:"sender"` +} + +func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte) *JSReceipt { + return &JSReceipt{ + contractCreation, + ethutil.Bytes2Hex(creationAddress), + ethutil.Bytes2Hex(hash), + ethutil.Bytes2Hex(address), + } +} diff --git a/ethpipe/world.go b/ethpipe/world.go index 72e116d09..4666362f9 100644 --- a/ethpipe/world.go +++ b/ethpipe/world.go @@ -30,6 +30,10 @@ func (self *World) Get(addr []byte) *Object { return &Object{self.State().GetStateObject(addr)} } +func (self *World) SafeGet(addr []byte) *Object { + return &Object{self.safeGet(addr)} +} + func (self *World) safeGet(addr []byte) *ethstate.StateObject { object := self.State().GetStateObject(addr) if object == nil { -- cgit From 7d95e8624a3bdca4a68b2a7ff6ed133264088cc1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 15 Aug 2014 16:19:10 +0200 Subject: Added message to closure && added change addresses --- ethpipe/pipe.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index a9da66ab8..8a81734cd 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -61,7 +61,7 @@ func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price * vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address())) - closure := ethvm.NewClosure(initiator, stateObject, object.Code, gas.BigInt(), price.BigInt()) + closure := ethvm.NewClosure(ðstate.Message{}, initiator, stateObject, object.Code, gas.BigInt(), price.BigInt()) ret, _, err := closure.Call(vm, data) return ret, err -- cgit From d79387c27e5bbbbed1d02cb9c57cbb7c5bd9fc33 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 17 Aug 2014 12:41:52 +0200 Subject: Mutan compile --- ethpipe/js_pipe.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index a2d3fdf10..2f1f90462 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -166,3 +166,12 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr return NewJSReciept(contractCreation, tx.CreationAddress(), tx.Hash(), keyPair.Address()), nil } + +func (self *JSPipe) CompileMutan(code string) string { + data, err := self.Pipe.CompileMutan(code) + if err != nil { + return err.Error() + } + + return ethutil.Bytes2Hex(data) +} -- cgit From 4008ff32c903e6894f5fb4fb69c795641641d192 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 17 Aug 2014 12:42:02 +0200 Subject: Mutan compile --- ethpipe/pipe.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ethpipe') diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index 8a81734cd..800a71139 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -148,3 +148,12 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price return tx.Hash(), nil } + +func (self *Pipe) CompileMutan(code string) ([]byte, error) { + data, err := ethutil.Compile(code, false) + if err != nil { + return nil, err + } + + return data, nil +} -- cgit From b0ae61c6521003d7861d89944e1d426e939535bb Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 18 Aug 2014 10:17:45 +0200 Subject: Removed the "Get" part --- ethpipe/js_pipe.go | 49 ++++++++++++++++++++++++++++++++++++++----------- ethpipe/js_types.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 11 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 2f1f90462..a2b1a4551 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -17,28 +17,28 @@ func NewJSPipe(eth ethchain.EthManager) *JSPipe { return &JSPipe{New(eth)} } -func (self *JSPipe) GetBlockByHash(strHash string) *JSBlock { +func (self *JSPipe) BlockByHash(strHash string) *JSBlock { hash := ethutil.Hex2Bytes(strHash) block := self.obj.BlockChain().GetBlock(hash) return NewJSBlock(block) } -func (self *JSPipe) GetKey() *JSKey { +func (self *JSPipe) Key() *JSKey { return NewJSKey(self.obj.KeyManager().KeyPair()) } -func (self *JSPipe) GetStateObject(addr string) *JSObject { +func (self *JSPipe) StateObject(addr string) *JSObject { object := &Object{self.World().safeGet(ethutil.Hex2Bytes(addr))} return NewJSObject(object) } -func (self *JSPipe) GetPeerCount() int { +func (self *JSPipe) PeerCount() int { return self.obj.PeerCount() } -func (self *JSPipe) GetPeers() []JSPeer { +func (self *JSPipe) Peers() []JSPeer { var peers []JSPeer for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() { p := peer.Value.(ethchain.Peer) @@ -51,23 +51,33 @@ func (self *JSPipe) GetPeers() []JSPeer { return peers } -func (self *JSPipe) GetIsMining() bool { +func (self *JSPipe) IsMining() bool { return self.obj.IsMining() } -func (self *JSPipe) GetIsListening() bool { +func (self *JSPipe) IsListening() bool { return self.obj.IsListening() } -func (self *JSPipe) GetCoinBase() string { +func (self *JSPipe) CoinBase() string { return ethutil.Bytes2Hex(self.obj.KeyManager().Address()) } -func (self *JSPipe) GetStorage(addr, storageAddr string) string { +func (self *JSPipe) BalanceAt(addr string) string { + return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance.String() +} + +func (self *JSPipe) NumberToHuman(balance string) string { + b := ethutil.Big(balance) + + return ethutil.CurrencyToString(b) +} + +func (self *JSPipe) StorageAt(addr, storageAddr string) string { return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)).Str() } -func (self *JSPipe) GetTxCountAt(address string) int { +func (self *JSPipe) TxCountAt(address string) int { return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce) } @@ -89,7 +99,7 @@ type KeyVal struct { Value string `json:"value"` } -func (self *JSPipe) GetEachStorage(addr string) string { +func (self *JSPipe) EachStorage(addr string) string { var values []KeyVal object := self.World().SafeGet(ethutil.Hex2Bytes(addr)) object.EachStorage(func(name string, value *ethutil.Value) { @@ -175,3 +185,20 @@ func (self *JSPipe) CompileMutan(code string) string { return ethutil.Bytes2Hex(data) } + +func (self *JSPipe) Messages(object map[string]interface{}) string { + filter := ethchain.NewFilterFromMap(object, self.obj) + + messages := filter.Find() + var msgs []JSMessage + for _, m := range messages { + msgs = append(msgs, NewJSMessage(m)) + } + + b, err := json.Marshal(msgs) + if err != nil { + return "{\"error\":" + err.Error() + "}" + } + + return string(b) +} diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index e1743486b..0fb3a3876 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/ethstate" "github.com/ethereum/eth-go/ethutil" ) @@ -175,3 +176,33 @@ func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte) ethutil.Bytes2Hex(address), } } + +type JSMessage struct { + To string `json:"to"` + From string `json:"from"` + Input string `json:"input"` + Output string `json:"output"` + Path int32 `json:"path"` + Origin string `json:"origin"` + Timestamp int32 `json:"timestamp"` + Coinbase string `json:"coinbase"` + Block string `json:"block"` + Number int32 `json:"number"` + Value string `json:"value"` +} + +func NewJSMessage(message *ethstate.Message) JSMessage { + return JSMessage{ + To: ethutil.Bytes2Hex(message.To), + From: ethutil.Bytes2Hex(message.From), + Input: ethutil.Bytes2Hex(message.Input), + Output: ethutil.Bytes2Hex(message.Output), + Path: int32(message.Path), + Origin: ethutil.Bytes2Hex(message.Origin), + Timestamp: int32(message.Timestamp), + Coinbase: ethutil.Bytes2Hex(message.Origin), + Block: ethutil.Bytes2Hex(message.Block), + Number: int32(message.Number.Int64()), + Value: message.Value.String(), + } +} -- cgit From b97ea0e447c24c0a85f63a7714a2eb221a7faccd Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 20 Aug 2014 09:59:09 +0200 Subject: Added JSFilter type --- ethpipe/js_pipe.go | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index a2b1a4551..0d0928fc3 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -2,10 +2,13 @@ package ethpipe import ( "encoding/json" + "fmt" "sync/atomic" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethcrypto" + "github.com/ethereum/eth-go/ethreact" + "github.com/ethereum/eth-go/ethstate" "github.com/ethereum/eth-go/ethutil" ) @@ -74,7 +77,8 @@ func (self *JSPipe) NumberToHuman(balance string) string { } func (self *JSPipe) StorageAt(addr, storageAddr string) string { - return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)).Str() + storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)) + return storage.BigInt().String() } func (self *JSPipe) TxCountAt(address string) int { @@ -186,10 +190,45 @@ func (self *JSPipe) CompileMutan(code string) string { return ethutil.Bytes2Hex(data) } +func (self *JSPipe) Watch(object map[string]interface{}) *JSFilter { + return NewJSFilterFromMap(object, self.Pipe.obj) + /*} else if str, ok := object.(string); ok { + println("str") + return NewJSFilterFromString(str, self.Pipe.obj) + */ +} + func (self *JSPipe) Messages(object map[string]interface{}) string { - filter := ethchain.NewFilterFromMap(object, self.obj) + filter := self.Watch(object) + + defer filter.Uninstall() + + return filter.Messages() + +} + +type JSFilter struct { + eth ethchain.EthManager + *ethchain.Filter + quit chan bool + + BlockCallback func(*ethchain.Block) + MessageCallback func(ethstate.Messages) +} + +func NewJSFilterFromMap(object map[string]interface{}, eth ethchain.EthManager) *JSFilter { + filter := &JSFilter{eth, ethchain.NewFilterFromMap(object, eth), make(chan bool), nil, nil} + + go filter.mainLoop() + + return filter +} - messages := filter.Find() +func NewJSFilterFromString(str string, eth ethchain.EthManager) *JSFilter { + return nil +} + +func (self *JSFilter) MessagesToJson(messages ethstate.Messages) string { var msgs []JSMessage for _, m := range messages { msgs = append(msgs, NewJSMessage(m)) @@ -202,3 +241,44 @@ func (self *JSPipe) Messages(object map[string]interface{}) string { return string(b) } + +func (self *JSFilter) Messages() string { + return self.MessagesToJson(self.Find()) +} + +func (self *JSFilter) mainLoop() { + blockChan := make(chan ethreact.Event, 1) + messageChan := make(chan ethreact.Event, 1) + // Subscribe to events + reactor := self.eth.Reactor() + reactor.Subscribe("newBlock", blockChan) + reactor.Subscribe("messages", messageChan) +out: + for { + select { + case <-self.quit: + break out + case block := <-blockChan: + if block, ok := block.Resource.(*ethchain.Block); ok { + if self.BlockCallback != nil { + self.BlockCallback(block) + } + } + case msg := <-messageChan: + if messages, ok := msg.Resource.(ethstate.Messages); ok { + if self.MessageCallback != nil { + msgs := self.FilterMessages(messages) + self.MessageCallback(msgs) + } + } + } + } +} + +func (self *JSFilter) Changed(object interface{}) { + fmt.Printf("%T\n", object) +} + +func (self *JSFilter) Uninstall() { + self.quit <- true +} -- cgit From 55a2f35a648ef70cdcc88bd751265e30831b54e5 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 20 Aug 2014 13:05:26 +0200 Subject: JS Filter --- ethpipe/js_pipe.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 0d0928fc3..4b0d6a849 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -1,6 +1,7 @@ package ethpipe import ( + "bytes" "encoding/json" "fmt" "sync/atomic" @@ -119,6 +120,28 @@ func (self *JSPipe) EachStorage(addr string) string { return string(valuesJson) } +func (self *JSPipe) ToAscii(str string) string { + padded := ethutil.RightPadBytes([]byte(str), 32) + + return "0x" + ethutil.Bytes2Hex(padded) +} + +func (self *JSPipe) FromAscii(str string) string { + if ethutil.IsHex(str) { + str = str[2:] + } + + return string(bytes.Trim(ethutil.Hex2Bytes(str), "\x00")) +} + +func (self *JSPipe) FromNumber(str string) string { + if ethutil.IsHex(str) { + str = str[2:] + } + + return ethutil.BigD(ethutil.Hex2Bytes(str)).String() +} + func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (*JSReceipt, error) { var hash []byte var contractCreation bool @@ -200,8 +223,7 @@ func (self *JSPipe) Watch(object map[string]interface{}) *JSFilter { func (self *JSPipe) Messages(object map[string]interface{}) string { filter := self.Watch(object) - - defer filter.Uninstall() + filter.Uninstall() return filter.Messages() @@ -247,8 +269,8 @@ func (self *JSFilter) Messages() string { } func (self *JSFilter) mainLoop() { - blockChan := make(chan ethreact.Event, 1) - messageChan := make(chan ethreact.Event, 1) + blockChan := make(chan ethreact.Event, 5) + messageChan := make(chan ethreact.Event, 5) // Subscribe to events reactor := self.eth.Reactor() reactor.Subscribe("newBlock", blockChan) @@ -267,8 +289,11 @@ out: case msg := <-messageChan: if messages, ok := msg.Resource.(ethstate.Messages); ok { if self.MessageCallback != nil { + println("messages!") msgs := self.FilterMessages(messages) - self.MessageCallback(msgs) + if len(msgs) > 0 { + self.MessageCallback(msgs) + } } } } -- cgit From 89c442cadbf995f09259b6a30a6d51989bd3d777 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 20 Aug 2014 13:36:54 +0200 Subject: Added block by number --- ethpipe/js_pipe.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 4b0d6a849..51de4ddbe 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -28,6 +28,14 @@ func (self *JSPipe) BlockByHash(strHash string) *JSBlock { return NewJSBlock(block) } +func (self *JSPipe) GetBlockByNumber(num int32) *JSBlock { + if num == -1 { + return NewJSBlock(self.obj.BlockChain().CurrentBlock) + } + + return NewJSBlock(self.obj.BlockChain().GetBlockByNumber(uint64(num))) +} + func (self *JSPipe) Key() *JSKey { return NewJSKey(self.obj.KeyManager().KeyPair()) } -- cgit From 79c64f6bca4fcfb257496be22c64f4b2faed7050 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 20 Aug 2014 16:40:19 +0200 Subject: Added block by hash or number --- ethpipe/js_pipe.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 51de4ddbe..8f08a7c5f 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -28,7 +28,7 @@ func (self *JSPipe) BlockByHash(strHash string) *JSBlock { return NewJSBlock(block) } -func (self *JSPipe) GetBlockByNumber(num int32) *JSBlock { +func (self *JSPipe) BlockByNumber(num int32) *JSBlock { if num == -1 { return NewJSBlock(self.obj.BlockChain().CurrentBlock) } @@ -36,6 +36,18 @@ func (self *JSPipe) GetBlockByNumber(num int32) *JSBlock { return NewJSBlock(self.obj.BlockChain().GetBlockByNumber(uint64(num))) } +func (self *JSPipe) Block(v interface{}) *JSBlock { + if n, ok := v.(int32); ok { + return self.BlockByNumber(n) + } else if str, ok := v.(string); ok { + return self.BlockByHash(str) + } else if f, ok := v.(float64); ok { // Don't ask ... + return self.BlockByNumber(int32(f)) + } + + return nil +} + func (self *JSPipe) Key() *JSKey { return NewJSKey(self.obj.KeyManager().KeyPair()) } -- cgit From b368549fd5d54ca5c73f424273a9d3896ad456a0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 21 Aug 2014 15:12:13 +0200 Subject: Always return something valid --- ethpipe/js_pipe.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 8f08a7c5f..b32e94a10 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -276,6 +276,11 @@ func (self *JSFilter) MessagesToJson(messages ethstate.Messages) string { msgs = append(msgs, NewJSMessage(m)) } + // Return an empty array instead of "null" + if len(msgs) == 0 { + return "[]" + } + b, err := json.Marshal(msgs) if err != nil { return "{\"error\":" + err.Error() + "}" -- cgit From 740081e2f7f3f76f7522753fd3c714e57ea22f3f Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 21 Aug 2014 21:06:42 +0200 Subject: Storage at changed to return bytes --- ethpipe/js_pipe.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index b32e94a10..eeece5179 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -99,7 +99,8 @@ func (self *JSPipe) NumberToHuman(balance string) string { func (self *JSPipe) StorageAt(addr, storageAddr string) string { storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)) - return storage.BigInt().String() + + return ethutil.Bytes2Hex(storage.Bytes()) } func (self *JSPipe) TxCountAt(address string) int { -- cgit From 6afc16399f9624663579ad72950b4ea3b887db57 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 25 Aug 2014 12:53:06 +0200 Subject: Block size --- ethpipe/js_types.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index 0fb3a3876..d9cbef12d 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -14,6 +14,7 @@ import ( // Block interface exposed to QML type JSBlock struct { ref *ethchain.Block + Size string `json:"size"` Number int `json:"number"` Hash string `json:"hash"` Transactions string `json:"transactions"` @@ -40,7 +41,7 @@ func NewJSBlock(block *ethchain.Block) *JSBlock { return nil } - return &JSBlock{ref: block, Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} + return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} } func (self *JSBlock) ToString() string { -- cgit From 0fea62ec6d33a83e602c804ee4b5b0a7896fd9c6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 8 Sep 2014 00:49:47 +0200 Subject: Make use of new list type for transactions instead of json --- ethpipe/js_types.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index d9cbef12d..8d2805f3d 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -1,7 +1,6 @@ package ethpipe import ( - "encoding/json" "strconv" "strings" @@ -13,16 +12,17 @@ import ( // Block interface exposed to QML type JSBlock struct { + //Transactions string `json:"transactions"` ref *ethchain.Block - Size string `json:"size"` - Number int `json:"number"` - Hash string `json:"hash"` - Transactions string `json:"transactions"` - Time int64 `json:"time"` - Coinbase string `json:"coinbase"` - Name string `json:"name"` - GasLimit string `json:"gasLimit"` - GasUsed string `json:"gasUsed"` + Size string `json:"size"` + Number int `json:"number"` + Hash string `json:"hash"` + Transactions *ethutil.List `json:"transactions"` + Time int64 `json:"time"` + Coinbase string `json:"coinbase"` + Name string `json:"name"` + GasLimit string `json:"gasLimit"` + GasUsed string `json:"gasUsed"` } // Creates a new QML Block from a chain block @@ -36,12 +36,16 @@ func NewJSBlock(block *ethchain.Block) *JSBlock { ptxs = append(ptxs, *NewJSTx(tx)) } - txJson, err := json.Marshal(ptxs) - if err != nil { - return nil - } + /* + txJson, err := json.Marshal(ptxs) + if err != nil { + return nil + } + return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} + */ + list := ethutil.NewList(ptxs) - return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} + return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: list, Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} } func (self *JSBlock) ToString() string { -- cgit From 7dacd7eb7818a336b3be99aea834093cf40a1b08 Mon Sep 17 00:00:00 2001 From: Cayman Nava Date: Sat, 6 Sep 2014 13:51:13 -0700 Subject: add pushtx to api Previously the software assumed use of an internal private key for use in all broadcasted transactions. This addition lets nodes relay pre-signed transactions originating from sources other than the node itself. --- ethpipe/js_pipe.go | 6 ++++++ ethpipe/pipe.go | 9 +++++++++ 2 files changed, 15 insertions(+) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index eeece5179..47cac2ca2 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -225,6 +225,12 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr return NewJSReciept(contractCreation, tx.CreationAddress(), tx.Hash(), keyPair.Address()), nil } +func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) { + tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) + self.obj.TxPool().QueueTransaction(tx) + return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil +} + func (self *JSPipe) CompileMutan(code string) string { data, err := self.Pipe.CompileMutan(code) if err != nil { diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index 800a71139..b7d3be041 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -149,6 +149,15 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price return tx.Hash(), nil } +func (self *Pipe) PushTx(tx *ethchain.Transaction) ([]byte, error) { + self.obj.TxPool().QueueTransaction(tx) + if tx.Recipient == nil { + logger.Infof("Contract addr %x", tx.CreationAddress()) + return tx.CreationAddress(), nil + } + return tx.Hash(), nil +} + func (self *Pipe) CompileMutan(code string) ([]byte, error) { data, err := ethutil.Compile(code, false) if err != nil { -- cgit From 2fb57b2ea7b7f697ddc4811c471d87116eae07cc Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 14 Sep 2014 00:13:23 +0200 Subject: Reworked filters --- ethpipe/js_pipe.go | 97 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 95 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index eeece5179..7ee183c84 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -3,12 +3,10 @@ package ethpipe import ( "bytes" "encoding/json" - "fmt" "sync/atomic" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethcrypto" - "github.com/ethereum/eth-go/ethreact" "github.com/ethereum/eth-go/ethstate" "github.com/ethereum/eth-go/ethutil" ) @@ -234,102 +232,11 @@ func (self *JSPipe) CompileMutan(code string) string { return ethutil.Bytes2Hex(data) } -func (self *JSPipe) Watch(object map[string]interface{}) *JSFilter { - return NewJSFilterFromMap(object, self.Pipe.obj) - /*} else if str, ok := object.(string); ok { - println("str") - return NewJSFilterFromString(str, self.Pipe.obj) - */ -} - -func (self *JSPipe) Messages(object map[string]interface{}) string { - filter := self.Watch(object) - filter.Uninstall() - - return filter.Messages() - -} - -type JSFilter struct { - eth ethchain.EthManager - *ethchain.Filter - quit chan bool - - BlockCallback func(*ethchain.Block) - MessageCallback func(ethstate.Messages) -} - -func NewJSFilterFromMap(object map[string]interface{}, eth ethchain.EthManager) *JSFilter { - filter := &JSFilter{eth, ethchain.NewFilterFromMap(object, eth), make(chan bool), nil, nil} - - go filter.mainLoop() - - return filter -} - -func NewJSFilterFromString(str string, eth ethchain.EthManager) *JSFilter { - return nil -} - -func (self *JSFilter) MessagesToJson(messages ethstate.Messages) string { +func ToJSMessages(messages ethstate.Messages) *ethutil.List { var msgs []JSMessage for _, m := range messages { msgs = append(msgs, NewJSMessage(m)) } - // Return an empty array instead of "null" - if len(msgs) == 0 { - return "[]" - } - - b, err := json.Marshal(msgs) - if err != nil { - return "{\"error\":" + err.Error() + "}" - } - - return string(b) -} - -func (self *JSFilter) Messages() string { - return self.MessagesToJson(self.Find()) -} - -func (self *JSFilter) mainLoop() { - blockChan := make(chan ethreact.Event, 5) - messageChan := make(chan ethreact.Event, 5) - // Subscribe to events - reactor := self.eth.Reactor() - reactor.Subscribe("newBlock", blockChan) - reactor.Subscribe("messages", messageChan) -out: - for { - select { - case <-self.quit: - break out - case block := <-blockChan: - if block, ok := block.Resource.(*ethchain.Block); ok { - if self.BlockCallback != nil { - self.BlockCallback(block) - } - } - case msg := <-messageChan: - if messages, ok := msg.Resource.(ethstate.Messages); ok { - if self.MessageCallback != nil { - println("messages!") - msgs := self.FilterMessages(messages) - if len(msgs) > 0 { - self.MessageCallback(msgs) - } - } - } - } - } -} - -func (self *JSFilter) Changed(object interface{}) { - fmt.Printf("%T\n", object) -} - -func (self *JSFilter) Uninstall() { - self.quit <- true + return ethutil.NewList(msgs) } -- cgit From 65a802c6787184951753ba2f79fdf60dce526721 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 22 Sep 2014 14:51:21 +0200 Subject: Re-wrote Call and Execute to use the new vm messages --- ethpipe/js_pipe.go | 30 +++++++++++++++++++++++------- ethpipe/pipe.go | 30 ++++++++++++++++-------------- 2 files changed, 39 insertions(+), 21 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 32212b26a..96990b671 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -85,10 +85,6 @@ func (self *JSPipe) CoinBase() string { return ethutil.Bytes2Hex(self.obj.KeyManager().Address()) } -func (self *JSPipe) BalanceAt(addr string) string { - return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance.String() -} - func (self *JSPipe) NumberToHuman(balance string) string { b := ethutil.Big(balance) @@ -101,10 +97,18 @@ func (self *JSPipe) StorageAt(addr, storageAddr string) string { return ethutil.Bytes2Hex(storage.Bytes()) } +func (self *JSPipe) BalanceAt(addr string) string { + return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance.String() +} + func (self *JSPipe) TxCountAt(address string) int { return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce) } +func (self *JSPipe) CodeAt(address string) string { + return ethutil.Bytes2Hex(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) +} + func (self *JSPipe) IsContract(address string) bool { return len(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) > 0 } @@ -118,6 +122,18 @@ func (self *JSPipe) SecretToAddress(key string) string { return ethutil.Bytes2Hex(pair.Address()) } +func (self *JSPipe) Execute(addr, value, gas, price, data string) (string, error) { + ret, err := self.ExecuteObject(&Object{ + self.World().safeGet(ethutil.Hex2Bytes(addr))}, + ethutil.Hex2Bytes(data), + ethutil.NewValue(value), + ethutil.NewValue(gas), + ethutil.NewValue(price), + ) + + return ethutil.Bytes2Hex(ret), err +} + type KeyVal struct { Key string `json:"key"` Value string `json:"value"` @@ -224,9 +240,9 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr } func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) { - tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) - self.obj.TxPool().QueueTransaction(tx) - return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil + tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) + self.obj.TxPool().QueueTransaction(tx) + return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil } func (self *JSPipe) CompileMutan(code string) string { diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index b7d3be041..7c3f491d3 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -1,6 +1,7 @@ package ethpipe import ( + "fmt" "strings" "github.com/ethereum/eth-go/ethchain" @@ -51,18 +52,19 @@ func (self *Pipe) Execute(addr []byte, data []byte, value, gas, price *ethutil.V func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { var ( - initiator = ethstate.NewStateObject([]byte{0}) - block = self.blockChain.CurrentBlock - stateObject = object.StateObject + initiator = ethstate.NewStateObject(self.obj.KeyManager().KeyPair().Address()) + block = self.blockChain.CurrentBlock ) - if self.Vm.State == nil { - self.Vm.State = self.World().State().Copy() - } + + self.Vm.State = self.World().State().Copy() vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address())) + vm.Verbose = true - closure := ethvm.NewClosure(ðstate.Message{}, initiator, stateObject, object.Code, gas.BigInt(), price.BigInt()) - ret, _, err := closure.Call(vm, data) + msg := ethvm.NewMessage(vm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) + ret, err := msg.Exec(object.Address(), initiator) + + fmt.Println("returned from call", ret, err) return ret, err } @@ -150,12 +152,12 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price } func (self *Pipe) PushTx(tx *ethchain.Transaction) ([]byte, error) { - self.obj.TxPool().QueueTransaction(tx) - if tx.Recipient == nil { - logger.Infof("Contract addr %x", tx.CreationAddress()) - return tx.CreationAddress(), nil - } - return tx.Hash(), nil + self.obj.TxPool().QueueTransaction(tx) + if tx.Recipient == nil { + logger.Infof("Contract addr %x", tx.CreationAddress()) + return tx.CreationAddress(), nil + } + return tx.Hash(), nil } func (self *Pipe) CompileMutan(code string) ([]byte, error) { -- cgit From 1118aaf840a6f6b4dd6b137f39ab895a0cbd5a56 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 24 Sep 2014 20:40:40 +0200 Subject: Temp work around --- ethpipe/js_types.go | 7 ------- 1 file changed, 7 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index 8d2805f3d..ccd585cf0 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -36,13 +36,6 @@ func NewJSBlock(block *ethchain.Block) *JSBlock { ptxs = append(ptxs, *NewJSTx(tx)) } - /* - txJson, err := json.Marshal(ptxs) - if err != nil { - return nil - } - return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: string(txJson), Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} - */ list := ethutil.NewList(ptxs) return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: list, Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} -- cgit From 9ed8dc7384deb932be624699d9f628d3d00ba31e Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 25 Sep 2014 16:57:49 +0200 Subject: Attempt to catch up from unknown block --- ethpipe/js_types.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index ccd585cf0..7266a5be4 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -23,12 +23,13 @@ type JSBlock struct { Name string `json:"name"` GasLimit string `json:"gasLimit"` GasUsed string `json:"gasUsed"` + PrevHash string `json:"prevHash"` } // Creates a new QML Block from a chain block func NewJSBlock(block *ethchain.Block) *JSBlock { if block == nil { - return nil + return &JSBlock{} } var ptxs []JSTransaction @@ -38,7 +39,14 @@ func NewJSBlock(block *ethchain.Block) *JSBlock { list := ethutil.NewList(ptxs) - return &JSBlock{ref: block, Size: block.Size().String(), Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: list, Time: block.Time, Coinbase: ethutil.Bytes2Hex(block.Coinbase)} + return &JSBlock{ + ref: block, Size: block.Size().String(), + Number: int(block.Number.Uint64()), GasUsed: block.GasUsed.String(), + GasLimit: block.GasLimit.String(), Hash: ethutil.Bytes2Hex(block.Hash()), + Transactions: list, Time: block.Time, + Coinbase: ethutil.Bytes2Hex(block.Coinbase), + PrevHash: ethutil.Bytes2Hex(block.PrevHash), + } } func (self *JSBlock) ToString() string { -- cgit From b8354124bebcd3988afd2f41c320f834a69b949e Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 26 Sep 2014 13:45:26 +0200 Subject: Added protocol caps accessors --- ethpipe/js_types.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index 7266a5be4..cf5686a4b 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -1,6 +1,7 @@ package ethpipe import ( + "fmt" "strconv" "strings" @@ -151,6 +152,7 @@ type JSPeer struct { Version string `json:"version"` LastResponse string `json:"lastResponse"` Latency string `json:"latency"` + Caps string `json:"caps"` } func NewJSPeer(peer ethchain.Peer) *JSPeer { @@ -164,7 +166,13 @@ func NewJSPeer(peer ethchain.Peer) *JSPeer { } ipAddress := strings.Join(ip, ".") - return &JSPeer{ref: &peer, Inbound: peer.Inbound(), LastSend: peer.LastSend().Unix(), LastPong: peer.LastPong(), Version: peer.Version(), Ip: ipAddress, Port: int(peer.Port()), Latency: peer.PingTime()} + var caps []string + capsIt := peer.Caps().NewIterator() + for capsIt.Next() { + caps = append(caps, capsIt.Value().Str()) + } + + return &JSPeer{ref: &peer, Inbound: peer.Inbound(), LastSend: peer.LastSend().Unix(), LastPong: peer.LastPong(), Version: peer.Version(), Ip: ipAddress, Port: int(peer.Port()), Latency: peer.PingTime(), Caps: fmt.Sprintf("%v", caps)} } type JSReceipt struct { -- cgit From 82be3054961864dfd5bbeaec2ab961f593203dbf Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 2 Oct 2014 17:03:15 +0200 Subject: Fixed inconsistencies --- ethpipe/js_pipe.go | 6 +++--- ethpipe/js_types.go | 8 ++++---- ethpipe/pipe.go | 10 ++++++---- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 96990b671..24a553dad 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -233,16 +233,16 @@ func (self *JSPipe) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr self.obj.TxPool().QueueTransaction(tx) if contractCreation { - logger.Infof("Contract addr %x", tx.CreationAddress()) + logger.Infof("Contract addr %x", tx.CreationAddress(self.World().State())) } - return NewJSReciept(contractCreation, tx.CreationAddress(), tx.Hash(), keyPair.Address()), nil + return NewJSReciept(contractCreation, tx.CreationAddress(self.World().State()), tx.Hash(), keyPair.Address()), nil } func (self *JSPipe) PushTx(txStr string) (*JSReceipt, error) { tx := ethchain.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) self.obj.TxPool().QueueTransaction(tx) - return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(), tx.Hash(), tx.Sender()), nil + return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil } func (self *JSPipe) CompileMutan(code string) string { diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index cf5686a4b..ca85da85a 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -35,7 +35,7 @@ func NewJSBlock(block *ethchain.Block) *JSBlock { var ptxs []JSTransaction for _, tx := range block.Transactions() { - ptxs = append(ptxs, *NewJSTx(tx)) + ptxs = append(ptxs, *NewJSTx(tx, block.State())) } list := ethutil.NewList(ptxs) @@ -64,7 +64,7 @@ func (self *JSBlock) GetTransaction(hash string) *JSTransaction { return nil } - return NewJSTx(tx) + return NewJSTx(tx, self.ref.State()) } type JSTransaction struct { @@ -83,11 +83,11 @@ type JSTransaction struct { Confirmations int `json:"confirmations"` } -func NewJSTx(tx *ethchain.Transaction) *JSTransaction { +func NewJSTx(tx *ethchain.Transaction, state *ethstate.State) *JSTransaction { hash := ethutil.Bytes2Hex(tx.Hash()) receiver := ethutil.Bytes2Hex(tx.Recipient) if receiver == "0000000000000000000000000000000000000000" { - receiver = ethutil.Bytes2Hex(tx.CreationAddress()) + receiver = ethutil.Bytes2Hex(tx.CreationAddress(state)) } sender := ethutil.Bytes2Hex(tx.Sender()) createsContract := tx.CreatesContract() diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index 7c3f491d3..f57b56ea0 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -143,9 +143,10 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price self.obj.TxPool().QueueTransaction(tx) if contractCreation { - logger.Infof("Contract addr %x", tx.CreationAddress()) + addr := tx.CreationAddress(self.World().State()) + logger.Infof("Contract addr %x\n", addr) - return tx.CreationAddress(), nil + return addr, nil } return tx.Hash(), nil @@ -154,8 +155,9 @@ func (self *Pipe) Transact(key *ethcrypto.KeyPair, rec []byte, value, gas, price func (self *Pipe) PushTx(tx *ethchain.Transaction) ([]byte, error) { self.obj.TxPool().QueueTransaction(tx) if tx.Recipient == nil { - logger.Infof("Contract addr %x", tx.CreationAddress()) - return tx.CreationAddress(), nil + addr := tx.CreationAddress(self.World().State()) + logger.Infof("Contract addr %x\n", addr) + return addr, nil } return tx.Hash(), nil } -- cgit From 0015ce1e353f52cca818d11f566b9a656fb85f24 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 7 Oct 2014 11:18:46 +0200 Subject: kick of bad peers --- ethpipe/js_types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_types.go b/ethpipe/js_types.go index ca85da85a..b8b546980 100644 --- a/ethpipe/js_types.go +++ b/ethpipe/js_types.go @@ -33,9 +33,9 @@ func NewJSBlock(block *ethchain.Block) *JSBlock { return &JSBlock{} } - var ptxs []JSTransaction + var ptxs []*JSTransaction for _, tx := range block.Transactions() { - ptxs = append(ptxs, *NewJSTx(tx, block.State())) + ptxs = append(ptxs, NewJSTx(tx, block.State())) } list := ethutil.NewList(ptxs) -- cgit From b417766b36f46316cbae6fa42815f1a519e5f733 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 8 Oct 2014 11:59:44 +0200 Subject: Minor tweaks for poc7 --- ethpipe/js_pipe.go | 2 ++ ethpipe/pipe.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 24a553dad..17c2261c7 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -3,6 +3,7 @@ package ethpipe import ( "bytes" "encoding/json" + "fmt" "sync/atomic" "github.com/ethereum/eth-go/ethchain" @@ -92,6 +93,7 @@ func (self *JSPipe) NumberToHuman(balance string) string { } func (self *JSPipe) StorageAt(addr, storageAddr string) string { + fmt.Println("get", addr, storageAddr) storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)) return ethutil.Bytes2Hex(storage.Bytes()) diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index f57b56ea0..1e1a2b835 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -61,7 +61,7 @@ func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price * vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address())) vm.Verbose = true - msg := ethvm.NewMessage(vm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) + msg := ethvm.NewExecution(vm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) ret, err := msg.Exec(object.Address(), initiator) fmt.Println("returned from call", ret, err) -- cgit From 4de3ad1712ce0fdc62b1acc27a3922b192e943c6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 8 Oct 2014 12:29:49 +0200 Subject: New block message --- ethpipe/js_pipe.go | 2 -- 1 file changed, 2 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 17c2261c7..24a553dad 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -3,7 +3,6 @@ package ethpipe import ( "bytes" "encoding/json" - "fmt" "sync/atomic" "github.com/ethereum/eth-go/ethchain" @@ -93,7 +92,6 @@ func (self *JSPipe) NumberToHuman(balance string) string { } func (self *JSPipe) StorageAt(addr, storageAddr string) string { - fmt.Println("get", addr, storageAddr) storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)) return ethutil.Bytes2Hex(storage.Bytes()) -- cgit From c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 14 Oct 2014 11:48:52 +0200 Subject: Refactored VM to two separate VMs; std & debug Standard VM should be about 10x faster than the debug VM. Some error checking has been removed, all of the log statements and therefor quite some unnecessary if-statements. --- ethpipe/pipe.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index 1e1a2b835..39ee0ef07 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -58,8 +58,7 @@ func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price * self.Vm.State = self.World().State().Copy() - vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address())) - vm.Verbose = true + vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()), ethvm.Type(ethutil.Config.VmType)) msg := ethvm.NewExecution(vm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) ret, err := msg.Exec(object.Address(), initiator) -- cgit From 93fcabd25189b447cc5c52523134cca2fa1d794e Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 16 Oct 2014 18:27:05 +0200 Subject: Fixed most of the tests --- ethpipe/vm_env.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethpipe') diff --git a/ethpipe/vm_env.go b/ethpipe/vm_env.go index 822a9e5c7..10ce0e561 100644 --- a/ethpipe/vm_env.go +++ b/ethpipe/vm_env.go @@ -32,3 +32,4 @@ func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty } func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) State() *ethstate.State { return self.state } +func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } -- cgit From 20c742e47406c13ebc6427951f6fcf1b0056ea26 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 18 Oct 2014 13:31:20 +0200 Subject: Moved ethvm => vm --- ethpipe/pipe.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index 39ee0ef07..5e5ff7000 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethstate" "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/eth-go/ethvm" + "github.com/ethereum/eth-go/vm" ) var logger = ethlog.NewLogger("PIPE") @@ -58,9 +58,9 @@ func (self *Pipe) ExecuteObject(object *Object, data []byte, value, gas, price * self.Vm.State = self.World().State().Copy() - vm := ethvm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()), ethvm.Type(ethutil.Config.VmType)) + evm := vm.New(NewEnv(self.Vm.State, block, value.BigInt(), initiator.Address()), vm.Type(ethutil.Config.VmType)) - msg := ethvm.NewExecution(vm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) + msg := vm.NewExecution(evm, object.Address(), data, gas.BigInt(), price.BigInt(), value.BigInt()) ret, err := msg.Exec(object.Address(), initiator) fmt.Println("returned from call", ret, err) -- cgit From 097ba56df59293f9225a8ecdc9e1c43a5ad891bb Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 20 Oct 2014 11:53:11 +0200 Subject: Renamed block_chain to chain_manager --- ethpipe/js_pipe.go | 6 +++--- ethpipe/pipe.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 24a553dad..873373b75 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -21,17 +21,17 @@ func NewJSPipe(eth ethchain.EthManager) *JSPipe { func (self *JSPipe) BlockByHash(strHash string) *JSBlock { hash := ethutil.Hex2Bytes(strHash) - block := self.obj.BlockChain().GetBlock(hash) + block := self.obj.ChainManager().GetBlock(hash) return NewJSBlock(block) } func (self *JSPipe) BlockByNumber(num int32) *JSBlock { if num == -1 { - return NewJSBlock(self.obj.BlockChain().CurrentBlock) + return NewJSBlock(self.obj.ChainManager().CurrentBlock) } - return NewJSBlock(self.obj.BlockChain().GetBlockByNumber(uint64(num))) + return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num))) } func (self *JSPipe) Block(v interface{}) *JSBlock { diff --git a/ethpipe/pipe.go b/ethpipe/pipe.go index 5e5ff7000..50507143c 100644 --- a/ethpipe/pipe.go +++ b/ethpipe/pipe.go @@ -21,7 +21,7 @@ type VmVars struct { type Pipe struct { obj ethchain.EthManager stateManager *ethchain.StateManager - blockChain *ethchain.BlockChain + blockChain *ethchain.ChainManager world *World Vm VmVars @@ -31,7 +31,7 @@ func New(obj ethchain.EthManager) *Pipe { pipe := &Pipe{ obj: obj, stateManager: obj.StateManager(), - blockChain: obj.BlockChain(), + blockChain: obj.ChainManager(), } pipe.world = NewWorld(pipe) -- cgit From 29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 23 Oct 2014 01:01:26 +0200 Subject: Updated the VM & VM tests * Stack Error shouldn't revert to previous state * Updated VM Test tool * Added Transfer method to VM Env --- ethpipe/js_pipe.go | 2 +- ethpipe/vm_env.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'ethpipe') diff --git a/ethpipe/js_pipe.go b/ethpipe/js_pipe.go index 873373b75..7eb33b4ea 100644 --- a/ethpipe/js_pipe.go +++ b/ethpipe/js_pipe.go @@ -98,7 +98,7 @@ func (self *JSPipe) StorageAt(addr, storageAddr string) string { } func (self *JSPipe) BalanceAt(addr string) string { - return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance.String() + return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance().String() } func (self *JSPipe) TxCountAt(address string) int { diff --git a/ethpipe/vm_env.go b/ethpipe/vm_env.go index 10ce0e561..7ef335800 100644 --- a/ethpipe/vm_env.go +++ b/ethpipe/vm_env.go @@ -5,6 +5,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethstate" + "github.com/ethereum/eth-go/vm" ) type VMEnv struct { @@ -33,3 +34,6 @@ func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) State() *ethstate.State { return self.state } func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } +func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { + return vm.Transfer(from, to, amount) +} -- cgit