Filtering
This commit is contained in:
@ -110,6 +110,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, state
|
||||
go self.eventMux.Post(TxPostEvent{tx})
|
||||
}
|
||||
|
||||
go self.eventMux.Post(state.Logs())
|
||||
|
||||
return receipt, txGas, err
|
||||
}
|
||||
|
||||
@ -155,25 +157,25 @@ done:
|
||||
return receipts, handled, unhandled, erroneous, err
|
||||
}
|
||||
|
||||
func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, msgs state.Messages, err error) {
|
||||
func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, err error) {
|
||||
// Processing a blocks may never happen simultaneously
|
||||
sm.mutex.Lock()
|
||||
defer sm.mutex.Unlock()
|
||||
|
||||
header := block.Header()
|
||||
if sm.bc.HasBlock(header.Hash()) {
|
||||
return nil, nil, &KnownBlockError{header.Number, header.Hash()}
|
||||
return nil, &KnownBlockError{header.Number, header.Hash()}
|
||||
}
|
||||
|
||||
if !sm.bc.HasBlock(header.ParentHash) {
|
||||
return nil, nil, ParentError(header.ParentHash)
|
||||
return nil, ParentError(header.ParentHash)
|
||||
}
|
||||
parent := sm.bc.GetBlock(header.ParentHash)
|
||||
|
||||
return sm.ProcessWithParent(block, parent)
|
||||
}
|
||||
|
||||
func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big.Int, messages state.Messages, err error) {
|
||||
func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big.Int, err error) {
|
||||
sm.lastAttemptedBlock = block
|
||||
|
||||
state := state.New(parent.Root(), sm.db)
|
||||
@ -227,7 +229,6 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big
|
||||
state.Sync()
|
||||
// Set the block hashes for the current messages
|
||||
state.Manifest().SetHash(block.Hash())
|
||||
messages = state.Manifest().Messages
|
||||
// Reset the manifest XXX We need this?
|
||||
state.Manifest().Reset()
|
||||
// Remove transactions from the pool
|
||||
@ -235,7 +236,7 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big
|
||||
|
||||
chainlogger.Infof("processed block #%d (%x...)\n", header.Number, block.Hash()[0:4])
|
||||
|
||||
return td, messages, nil
|
||||
return td, nil
|
||||
}
|
||||
|
||||
// Validates the current block. Returns an error if the block was invalid,
|
||||
|
@ -359,7 +359,7 @@ func (bc *ChainManager) Stop() {
|
||||
|
||||
func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
||||
for _, block := range chain {
|
||||
td, messages, err := self.processor.Process(block)
|
||||
td, err := self.processor.Process(block)
|
||||
if err != nil {
|
||||
if IsKnownBlockErr(err) {
|
||||
continue
|
||||
@ -391,7 +391,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
||||
self.mu.Unlock()
|
||||
|
||||
self.eventMux.Post(NewBlockEvent{block})
|
||||
self.eventMux.Post(messages)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -2,6 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
@ -130,6 +131,7 @@ func (self *Filter) Find() state.Logs {
|
||||
|
||||
func includes(addresses [][]byte, a []byte) (found bool) {
|
||||
for _, addr := range addresses {
|
||||
fmt.Println("INCLUDES", addr, a)
|
||||
if bytes.Compare(addr, a) == 0 {
|
||||
return true
|
||||
}
|
||||
@ -139,20 +141,25 @@ func includes(addresses [][]byte, a []byte) (found bool) {
|
||||
}
|
||||
|
||||
func (self *Filter) FilterLogs(logs state.Logs) state.Logs {
|
||||
fmt.Println("FILTER LOGS", self.topics)
|
||||
var ret state.Logs
|
||||
|
||||
// Filter the logs for interesting stuff
|
||||
for _, log := range logs {
|
||||
fmt.Println(log)
|
||||
|
||||
if len(self.address) > 0 && !bytes.Equal(self.address, log.Address()) {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, topic := range self.topics {
|
||||
fmt.Println("TOPIC:", topic)
|
||||
if !includes(log.Topics(), topic) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("APPENDED")
|
||||
ret = append(ret, log)
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
)
|
||||
import "math/big"
|
||||
|
||||
type BlockProcessor interface {
|
||||
Process(*Block) (*big.Int, state.Messages, error)
|
||||
Process(*Block) (*big.Int, error)
|
||||
}
|
||||
|
Reference in New Issue
Block a user