From 148de1c8757413f171dbf2fd3e8e5a5976eb7dc9 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 14 Dec 2014 18:09:33 +0000 Subject: adapt xeth pkg to new backend. FIXME JSPeer peer info --- xeth/hexface.go | 9 ++------ xeth/js_types.go | 65 +++++++++++++++++++++++++++----------------------------- xeth/world.go | 5 ++--- 3 files changed, 35 insertions(+), 44 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index c1f49453d..524b68210 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -3,7 +3,6 @@ package xeth import ( "bytes" "encoding/json" - "sync/atomic" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -63,12 +62,8 @@ func (self *JSXEth) PeerCount() int { func (self *JSXEth) Peers() []JSPeer { var peers []JSPeer - for peer := self.obj.Peers().Front(); peer != nil; peer = peer.Next() { - p := peer.Value.(core.Peer) - // we only want connected peers - if atomic.LoadInt32(p.Connected()) != 0 { - peers = append(peers, *NewJSPeer(p)) - } + for _, peer := range self.obj.Peers() { + peers = append(peers, *NewJSPeer(peer)) } return peers diff --git a/xeth/js_types.go b/xeth/js_types.go index da26439cf..1d9faa190 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -1,14 +1,13 @@ package xeth import ( - "fmt" - "strconv" "strings" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/state" ) @@ -155,38 +154,36 @@ func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) * // Peer interface exposed to QML type JSPeer struct { - ref *core.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"` - Caps string `json:"caps"` -} - -func NewJSPeer(peer core.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, ".") - - var caps []string - capsIt := peer.Caps().NewIterator() - for capsIt.Next() { - cap := capsIt.Value().Get(0).Str() - ver := capsIt.Value().Get(1).Uint() - caps = append(caps, fmt.Sprintf("%s/%d", cap, ver)) - } - - 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: "[" + strings.Join(caps, ", ") + "]"} + ref *p2p.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"` + // Caps string `json:"caps"` +} + +func NewJSPeer(peer *p2p.Peer) *JSPeer { + + // var ip []string + // for _, i := range peer.Host() { + // ip = append(ip, strconv.Itoa(int(i))) + // } + // ipAddress := strings.Join(ip, ".") + + // var caps []string + // capsIt := peer.Caps().NewIterator() + // for capsIt.Next() { + // cap := capsIt.Value().Get(0).Str() + // ver := capsIt.Value().Get(1).Uint() + // caps = append(caps, fmt.Sprintf("%s/%d", cap, ver)) + // } + + return &JSPeer{ref: peer} + // 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: "[" + strings.Join(caps, ", ") + "]"} } type JSReceipt struct { diff --git a/xeth/world.go b/xeth/world.go index 956ef1e15..008a08423 100644 --- a/xeth/world.go +++ b/xeth/world.go @@ -1,8 +1,7 @@ package xeth import ( - "container/list" - + "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/state" ) @@ -55,7 +54,7 @@ func (self *World) IsListening() bool { return self.pipe.obj.IsListening() } -func (self *World) Peers() *list.List { +func (self *World) Peers() []*p2p.Peer { return self.pipe.obj.Peers() } -- cgit v1.2.3 From 2d09e67713757e2a80eb614562c97f962af36cf7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 13:17:24 +0100 Subject: Updated to new methods --- xeth/hexface.go | 2 +- xeth/pipe.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index c1f49453d..75ec5f43d 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -29,7 +29,7 @@ func (self *JSXEth) BlockByHash(strHash string) *JSBlock { func (self *JSXEth) BlockByNumber(num int32) *JSBlock { if num == -1 { - return NewJSBlock(self.obj.ChainManager().CurrentBlock) + return NewJSBlock(self.obj.ChainManager().CurrentBlock()) } return NewJSBlock(self.obj.ChainManager().GetBlockByNumber(uint64(num))) diff --git a/xeth/pipe.go b/xeth/pipe.go index a8d8ed999..1e4d0ec60 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -82,7 +82,7 @@ func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.V func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { var ( initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) - block = self.chainManager.CurrentBlock + block = self.chainManager.CurrentBlock() ) self.Vm.State = self.World().State().Copy() -- cgit v1.2.3 From db494170dc819b1eb0d267b6e1ab36c6cfb63569 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 15:18:13 +0100 Subject: Created generic message (easy for testing) --- xeth/hexface.go | 4 ++-- xeth/js_types.go | 10 +++++----- xeth/pipe.go | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 75ec5f43d..8fb42b4db 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -216,7 +216,7 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr return "", err } if types.IsContractAddr(to) { - return ethutil.Bytes2Hex(tx.CreationAddress(nil)), nil + return ethutil.Bytes2Hex(core.AddressFromMessage(tx)), nil } return ethutil.Bytes2Hex(tx.Hash()), nil @@ -229,7 +229,7 @@ func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { return nil, err } - return NewJSReciept(tx.CreatesContract(), tx.CreationAddress(self.World().State()), tx.Hash(), tx.Sender()), nil + return NewJSReciept(tx.CreatesContract(), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil } func (self *JSXEth) CompileMutan(code string) string { diff --git a/xeth/js_types.go b/xeth/js_types.go index da26439cf..2d6ee91bc 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -97,21 +97,21 @@ type JSTransaction struct { func NewJSTx(tx *types.Transaction, state *state.StateDB) *JSTransaction { hash := ethutil.Bytes2Hex(tx.Hash()) - receiver := ethutil.Bytes2Hex(tx.Recipient) + receiver := ethutil.Bytes2Hex(tx.To()) if receiver == "0000000000000000000000000000000000000000" { - receiver = ethutil.Bytes2Hex(tx.CreationAddress(state)) + receiver = ethutil.Bytes2Hex(core.AddressFromMessage(tx)) } sender := ethutil.Bytes2Hex(tx.Sender()) createsContract := tx.CreatesContract() var data string if tx.CreatesContract() { - data = strings.Join(core.Disassemble(tx.Data), "\n") + data = strings.Join(core.Disassemble(tx.Data()), "\n") } else { - data = ethutil.Bytes2Hex(tx.Data) + 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)} + 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 { diff --git a/xeth/pipe.go b/xeth/pipe.go index 1e4d0ec60..06820cc86 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -134,7 +134,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et state := self.chainManager.TransState() nonce := state.GetNonce(key.Address()) - tx.Nonce = nonce + tx.SetNonce(nonce) tx.Sign(key.PrivateKey) // Do some pre processing for our "pre" events and hooks @@ -150,7 +150,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et state.SetNonce(key.Address(), nonce+1) if contractCreation { - addr := tx.CreationAddress(self.World().State()) + addr := core.AddressFromMessage(tx) pipelogger.Infof("Contract addr %x\n", addr) } @@ -163,8 +163,8 @@ func (self *XEth) PushTx(tx *types.Transaction) ([]byte, error) { return nil, err } - if tx.Recipient == nil { - addr := tx.CreationAddress(self.World().State()) + if tx.To() == nil { + addr := core.AddressFromMessage(tx) pipelogger.Infof("Contract addr %x\n", addr) return addr, nil } -- cgit v1.2.3 From 5ad473d7581b92811c3a3e035274a82fc5568f57 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 15:33:22 +0100 Subject: Moved methods to messages --- xeth/hexface.go | 2 +- xeth/js_types.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 8fb42b4db..bfd2dddd9 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -229,7 +229,7 @@ func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { return nil, err } - return NewJSReciept(tx.CreatesContract(), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil + return NewJSReciept(core.MessageCreatesContract(tx), core.AddressFromMessage(tx), tx.Hash(), tx.From()), nil } func (self *JSXEth) CompileMutan(code string) string { diff --git a/xeth/js_types.go b/xeth/js_types.go index 2d6ee91bc..62867d6a9 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -102,16 +102,16 @@ func NewJSTx(tx *types.Transaction, state *state.StateDB) *JSTransaction { receiver = ethutil.Bytes2Hex(core.AddressFromMessage(tx)) } sender := ethutil.Bytes2Hex(tx.Sender()) - createsContract := tx.CreatesContract() + createsContract := core.MessageCreatesContract(tx) var data string - if tx.CreatesContract() { + if createsContract { data = strings.Join(core.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())} + return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: 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 { -- cgit v1.2.3 From 59ef6e36931c980ba15babfb3680514635faebf6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 19 Dec 2014 00:18:52 +0100 Subject: Cleaned up objects --- xeth/vm_env.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'xeth') diff --git a/xeth/vm_env.go b/xeth/vm_env.go index ce53e9a30..7fb674a94 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -47,9 +47,7 @@ func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { } func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution { - evm := vm.New(self, vm.DebugVmTy) - - return core.NewExecution(evm, addr, data, gas, price, value) + return core.NewExecution(self, addr, data, gas, price, value) } func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) { -- cgit v1.2.3 From 4cd79d8ddd7608d60344b13fe4bda7315429d1d9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 23 Dec 2014 13:48:44 +0100 Subject: Refactored block & Transaction * Includes new rlp decoder --- xeth/js_types.go | 20 ++++++++++---------- xeth/pipe.go | 2 +- xeth/vm_env.go | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'xeth') diff --git a/xeth/js_types.go b/xeth/js_types.go index 04018f6a5..4bb1f4e7d 100644 --- a/xeth/js_types.go +++ b/xeth/js_types.go @@ -42,21 +42,21 @@ func NewJSBlock(block *types.Block) *JSBlock { } txlist := ethutil.NewList(ptxs) - puncles := make([]*JSBlock, len(block.Uncles)) - for i, uncle := range block.Uncles { - puncles[i] = NewJSBlock(uncle) + puncles := make([]*JSBlock, len(block.Uncles())) + for i, uncle := range block.Uncles() { + puncles[i] = NewJSBlock(types.NewBlockWithHeader(uncle)) } ulist := ethutil.NewList(puncles) 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()), + Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(), + GasLimit: block.GasLimit().String(), Hash: ethutil.Bytes2Hex(block.Hash()), Transactions: txlist, Uncles: ulist, - Time: block.Time, - Coinbase: ethutil.Bytes2Hex(block.Coinbase), - PrevHash: ethutil.Bytes2Hex(block.PrevHash), - Bloom: ethutil.Bytes2Hex(block.LogsBloom), + Time: block.Time(), + Coinbase: ethutil.Bytes2Hex(block.Coinbase()), + PrevHash: ethutil.Bytes2Hex(block.ParentHash()), + Bloom: ethutil.Bytes2Hex(block.Bloom()), Raw: block.String(), } } @@ -70,7 +70,7 @@ func (self *JSBlock) ToString() string { } func (self *JSBlock) GetTransaction(hash string) *JSTransaction { - tx := self.ref.GetTransaction(ethutil.Hex2Bytes(hash)) + tx := self.ref.Transaction(ethutil.Hex2Bytes(hash)) if tx == nil { return nil } diff --git a/xeth/pipe.go b/xeth/pipe.go index 06820cc86..775d5cfc5 100644 --- a/xeth/pipe.go +++ b/xeth/pipe.go @@ -140,7 +140,7 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et // Do some pre processing for our "pre" events and hooks block := self.chainManager.NewBlock(key.Address()) coinbase := state.GetStateObject(key.Address()) - coinbase.SetGasPool(block.GasLimit) + coinbase.SetGasPool(block.GasLimit()) self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) err := self.obj.TxPool().Add(tx) diff --git a/xeth/vm_env.go b/xeth/vm_env.go index 7fb674a94..7633e0640 100644 --- a/xeth/vm_env.go +++ b/xeth/vm_env.go @@ -28,15 +28,15 @@ func NewEnv(state *state.StateDB, block *types.Block, value *big.Int, sender []b } 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) BlockNumber() *big.Int { return self.block.Number() } +func (self *VMEnv) PrevHash() []byte { return self.block.ParentHash() } +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) GasLimit() *big.Int { return self.block.GasLimit() } func (self *VMEnv) Value() *big.Int { return self.value } func (self *VMEnv) State() *state.StateDB { return self.state } -func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } func (self *VMEnv) Depth() int { return self.depth } func (self *VMEnv) SetDepth(i int) { self.depth = i } func (self *VMEnv) AddLog(log state.Log) { -- cgit v1.2.3 From 780abaec988df302e0c98f1a35e9af35b5623746 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 23 Dec 2014 18:35:36 +0100 Subject: Switched to new trie --- xeth/hexface.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'xeth') diff --git a/xeth/hexface.go b/xeth/hexface.go index 6c084f947..c3d8cef86 100644 --- a/xeth/hexface.go +++ b/xeth/hexface.go @@ -138,10 +138,10 @@ type KeyVal struct { func (self *JSXEth) EachStorage(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())}) - }) + it := object.Trie().Iterator() + for it.Next() { + values = append(values, KeyVal{ethutil.Bytes2Hex(it.Key), ethutil.Bytes2Hex(it.Value)}) + } valuesJson, err := json.Marshal(values) if err != nil { -- cgit v1.2.3