Added a callback mechanism to chain adding.

Not sure if this is the right approach. Why? BlockChain shouldn't need
the "Ethereum" object. BlockChain shouldn't need to worry about
notifying listeners or message propagation.
This commit is contained in:
obscuren
2014-11-18 19:44:17 +01:00
parent a1b6a9ac29
commit f8d0cd9906
4 changed files with 17 additions and 13 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/chain"
"github.com/ethereum/go-ethereum/chain/types"
@ -218,8 +219,10 @@ func (self *Miner) mine() {
if err != nil {
minerlogger.Infoln(err)
} else {
chainMan.InsertChain(lchain)
//self.eth.EventMux().Post(chain.NewBlockEvent{block})
chainMan.InsertChain(lchain, func(block *types.Block, _ state.Messages) {
self.eth.EventMux().Post(chain.NewBlockEvent{block})
})
self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val})
minerlogger.Infof("🔨 Mined block %x\n", block.Hash())