aboutsummaryrefslogtreecommitdiffstats
path: root/chain
diff options
context:
space:
mode:
Diffstat (limited to 'chain')
-rw-r--r--chain/block_manager.go31
-rw-r--r--chain/chain_manager.go1
-rw-r--r--chain/receipt.go65
-rw-r--r--chain/transaction.go47
4 files changed, 86 insertions, 58 deletions
diff --git a/chain/block_manager.go b/chain/block_manager.go
index b7c805129..4431e3ba9 100644
--- a/chain/block_manager.go
+++ b/chain/block_manager.go
@@ -159,7 +159,9 @@ done:
txGas.Sub(txGas, st.gas)
cumulative := new(big.Int).Set(totalUsedGas.Add(totalUsedGas, txGas))
- receipt := &Receipt{ethutil.CopyBytes(state.Root().([]byte)), cumulative, LogsBloom(state.Logs()).Bytes(), state.Logs()}
+ bloom := ethutil.LeftPadBytes(LogsBloom(state.Logs()).Bytes(), 64)
+ receipt := &Receipt{ethutil.CopyBytes(state.Root()), cumulative, bloom, state.Logs()}
+ //fmt.Println(receipt)
// Notify all subscribers
go self.eth.EventMux().Post(TxPostEvent{tx})
@@ -213,13 +215,15 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
if err != nil {
return
}
- block.SetReceipts(receipts)
+ //block.SetReceipts(receipts)
- txSha := DeriveSha(block.transactions)
- if bytes.Compare(txSha, block.TxSha) != 0 {
- err = fmt.Errorf("Error validating transaction sha. Received %x, got %x", block.TxSha, txSha)
- return
- }
+ /*
+ txSha := DeriveSha(block.transactions)
+ if bytes.Compare(txSha, block.TxSha) != 0 {
+ err = fmt.Errorf("Error validating transaction sha. Received %x, got %x", block.TxSha, txSha)
+ return
+ }
+ */
receiptSha := DeriveSha(receipts)
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
@@ -255,13 +259,18 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
// Sync the current block's state to the database and cancelling out the deferred Undo
state.Sync()
- // TODO at this point we should also insert LOGS in to a database
-
- sm.transState = state.Copy()
-
messages := state.Manifest().Messages
state.Manifest().Reset()
+ /*
+ sm.eth.ChainManager().SetTotalDifficulty(td)
+ sm.eth.ChainManager().add(block)
+ sm.eth.EventMux().Post(NewBlockEvent{block})
+ sm.eth.EventMux().Post(messages)
+ */
+
+ sm.transState = state.Copy()
+
sm.eth.TxPool().RemoveSet(block.Transactions())
return td, messages, nil
diff --git a/chain/chain_manager.go b/chain/chain_manager.go
index 46e0703c1..217a50103 100644
--- a/chain/chain_manager.go
+++ b/chain/chain_manager.go
@@ -337,6 +337,7 @@ func (self *ChainManager) InsertChain(chain *BlockChain) {
func (self *ChainManager) TestChain(chain *BlockChain) (td *big.Int, err error) {
self.workingChain = chain
+ defer func() { self.workingChain = nil }()
for e := chain.Front(); e != nil; e = e.Next() {
var (
diff --git a/chain/receipt.go b/chain/receipt.go
new file mode 100644
index 000000000..742271fa3
--- /dev/null
+++ b/chain/receipt.go
@@ -0,0 +1,65 @@
+package chain
+
+import (
+ "bytes"
+ "fmt"
+ "math/big"
+
+ "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/state"
+)
+
+type Receipt struct {
+ PostState []byte
+ CumulativeGasUsed *big.Int
+ Bloom []byte
+ logs state.Logs
+}
+
+func NewRecieptFromValue(val *ethutil.Value) *Receipt {
+ r := &Receipt{}
+ r.RlpValueDecode(val)
+
+ return r
+}
+
+func (self *Receipt) RlpValueDecode(decoder *ethutil.Value) {
+ self.PostState = decoder.Get(0).Bytes()
+ self.CumulativeGasUsed = decoder.Get(1).BigInt()
+ self.Bloom = decoder.Get(2).Bytes()
+
+ it := decoder.Get(3).NewIterator()
+ for it.Next() {
+ self.logs = append(self.logs, state.NewLogFromValue(it.Value()))
+ }
+}
+
+func (self *Receipt) RlpData() interface{} {
+ fmt.Println(self.logs.RlpData())
+ return []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs.RlpData()}
+}
+
+func (self *Receipt) RlpEncode() []byte {
+ return ethutil.Encode(self.RlpData())
+}
+
+func (self *Receipt) Cmp(other *Receipt) bool {
+ if bytes.Compare(self.PostState, other.PostState) != 0 {
+ return false
+ }
+
+ return true
+}
+
+func (self *Receipt) String() string {
+ return fmt.Sprintf(`Receipt: %x
+cumulative gas: %v
+bloom: %x
+logs: %v
+rlp: %x`, self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs, self.RlpEncode())
+}
+
+type Receipts []*Receipt
+
+func (self Receipts) Len() int { return len(self) }
+func (self Receipts) GetRlp(i int) []byte { return ethutil.Rlp(self[i]) }
diff --git a/chain/transaction.go b/chain/transaction.go
index d2d6a8e14..d81a0ea1b 100644
--- a/chain/transaction.go
+++ b/chain/transaction.go
@@ -1,7 +1,6 @@
package chain
import (
- "bytes"
"fmt"
"math/big"
@@ -201,52 +200,6 @@ func (tx *Transaction) String() string {
tx.s)
}
-type Receipt struct {
- PostState []byte
- CumulativeGasUsed *big.Int
- Bloom []byte
- logs state.Logs
-}
-
-func NewRecieptFromValue(val *ethutil.Value) *Receipt {
- r := &Receipt{}
- r.RlpValueDecode(val)
-
- return r
-}
-
-func (self *Receipt) RlpValueDecode(decoder *ethutil.Value) {
- self.PostState = decoder.Get(0).Bytes()
- self.CumulativeGasUsed = decoder.Get(1).BigInt()
- self.Bloom = decoder.Get(2).Bytes()
-
- it := decoder.Get(3).NewIterator()
- for it.Next() {
- self.logs = append(self.logs, state.NewLogFromValue(it.Value()))
- }
-}
-
-func (self *Receipt) RlpData() interface{} {
- return []interface{}{self.PostState, self.CumulativeGasUsed, self.Bloom, self.logs.RlpData()}
-}
-
-func (self *Receipt) RlpEncode() []byte {
- return ethutil.Encode(self.RlpData())
-}
-
-func (self *Receipt) Cmp(other *Receipt) bool {
- if bytes.Compare(self.PostState, other.PostState) != 0 {
- return false
- }
-
- return true
-}
-
-type Receipts []*Receipt
-
-func (self Receipts) Len() int { return len(self) }
-func (self Receipts) GetRlp(i int) []byte { return ethutil.Rlp(self[i]) }
-
// Transaction slice type for basic sorting
type Transactions []*Transaction