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