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:
@ -13,6 +13,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/chain/types"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
"github.com/ethereum/go-ethereum/wire"
|
||||
)
|
||||
|
||||
@ -310,10 +311,6 @@ out:
|
||||
}
|
||||
}
|
||||
|
||||
// TODO figure out whether we were catching up
|
||||
// If caught up and just a new block has been propagated:
|
||||
// sm.eth.EventMux().Post(NewBlockEvent{block})
|
||||
// otherwise process and don't emit anything
|
||||
if len(blocks) > 0 {
|
||||
chainManager := self.eth.ChainManager()
|
||||
// Test and import
|
||||
@ -335,10 +332,13 @@ out:
|
||||
self.peer = nil
|
||||
} else {
|
||||
if !chain.IsTDError(err) {
|
||||
chainManager.InsertChain(bchain)
|
||||
for _, block := range blocks {
|
||||
chainManager.InsertChain(bchain, func(block *types.Block, messages state.Messages) {
|
||||
self.eth.EventMux().Post(chain.NewBlockEvent{block})
|
||||
self.eth.EventMux().Post(messages)
|
||||
|
||||
self.Remove(block.Hash())
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user