diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-07 20:17:48 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-07 20:17:48 +0800 |
commit | fed3e6a808921fb8274b50043c5c39a24a1bbccf (patch) | |
tree | d632e95cfce78bd9a99a52bf7f30ee3ff980dfd3 /core/chain_manager.go | |
parent | 032ab665299d75bffc25260e8fa477ace19db06a (diff) | |
download | go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.tar.gz go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.tar.zst go-tangerine-fed3e6a808921fb8274b50043c5c39a24a1bbccf.zip |
Refactored ethutil.Config.Db out
Diffstat (limited to 'core/chain_manager.go')
-rw-r--r-- | core/chain_manager.go | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go index e73ea6378..2d4001f0f 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -55,6 +55,7 @@ func CalcGasLimit(parent, block *types.Block) *big.Int { type ChainManager struct { //eth EthManager + db ethutil.Database processor types.BlockProcessor eventMux *event.TypeMux genesisBlock *types.Block @@ -96,13 +97,9 @@ func (self *ChainManager) CurrentBlock() *types.Block { return self.currentBlock } -func NewChainManager(mux *event.TypeMux) *ChainManager { - bc := &ChainManager{} - bc.genesisBlock = GenesisBlock() - bc.eventMux = mux - +func NewChainManager(db ethutil.Database, mux *event.TypeMux) *ChainManager { + bc := &ChainManager{db: db, genesisBlock: GenesisBlock(db), eventMux: mux} bc.setLastBlock() - bc.transState = bc.State().Copy() return bc @@ -120,7 +117,7 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) { } func (self *ChainManager) State() *state.StateDB { - return state.New(self.CurrentBlock().Trie()) + return state.New(self.CurrentBlock().Root(), self.db) } func (self *ChainManager) TransState() *state.StateDB { @@ -128,7 +125,7 @@ func (self *ChainManager) TransState() *state.StateDB { } func (bc *ChainManager) setLastBlock() { - data, _ := ethutil.Config.Db.Get([]byte("LastBlock")) + data, _ := bc.db.Get([]byte("LastBlock")) if len(data) != 0 { var block types.Block rlp.Decode(bytes.NewReader(data), &block) @@ -137,7 +134,7 @@ func (bc *ChainManager) setLastBlock() { bc.lastBlockNumber = block.Header().Number.Uint64() // Set the last know difficulty (might be 0x0 as initial value, Genesis) - bc.td = ethutil.BigD(ethutil.Config.Db.LastKnownTD()) + bc.td = ethutil.BigD(bc.db.LastKnownTD()) } else { bc.Reset() } @@ -183,7 +180,7 @@ func (bc *ChainManager) Reset() { defer bc.mu.Unlock() for block := bc.currentBlock; block != nil; block = bc.GetBlock(block.Header().ParentHash) { - ethutil.Config.Db.Delete(block.Hash()) + bc.db.Delete(block.Hash()) } // Prepare the genesis block @@ -210,7 +207,7 @@ func (self *ChainManager) Export() []byte { func (bc *ChainManager) insert(block *types.Block) { encodedBlock := ethutil.Encode(block) - ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock) + bc.db.Put([]byte("LastBlock"), encodedBlock) bc.currentBlock = block bc.lastBlockHash = block.Hash() } @@ -219,7 +216,7 @@ func (bc *ChainManager) write(block *types.Block) { bc.writeBlockInfo(block) encodedBlock := ethutil.Encode(block) - ethutil.Config.Db.Put(block.Hash(), encodedBlock) + bc.db.Put(block.Hash(), encodedBlock) } // Accessors @@ -229,7 +226,7 @@ func (bc *ChainManager) Genesis() *types.Block { // Block fetching methods func (bc *ChainManager) HasBlock(hash []byte) bool { - data, _ := ethutil.Config.Db.Get(hash) + data, _ := bc.db.Get(hash) return len(data) != 0 } @@ -254,7 +251,7 @@ func (self *ChainManager) GetBlockHashesFromHash(hash []byte, max uint64) (chain } func (self *ChainManager) GetBlock(hash []byte) *types.Block { - data, _ := ethutil.Config.Db.Get(hash) + data, _ := self.db.Get(hash) if len(data) == 0 { return nil } @@ -286,7 +283,7 @@ func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block { } func (bc *ChainManager) setTotalDifficulty(td *big.Int) { - ethutil.Config.Db.Put([]byte("LTD"), td.Bytes()) + bc.db.Put([]byte("LTD"), td.Bytes()) bc.td = td } @@ -348,7 +345,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { self.setTotalDifficulty(td) self.insert(block) - self.transState = state.New(cblock.Trie().Copy()) + self.transState = state.New(cblock.Root(), self.db) //state.New(cblock.Trie().Copy()) } } |