aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/block_chain.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethchain/block_chain.go')
-rw-r--r--ethchain/block_chain.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go
index 1e29f1188..7c9b60fc5 100644
--- a/ethchain/block_chain.go
+++ b/ethchain/block_chain.go
@@ -164,6 +164,7 @@ func (bc *BlockChain) setLastBlock() {
bc.Add(bc.genesisBlock)
fk := append([]byte("bloom"), bc.genesisBlock.Hash()...)
bc.Ethereum.Db().Put(fk, make([]byte, 255))
+ bc.CurrentBlock = bc.genesisBlock
}
// Set the last know difficulty (might be 0x0 as initial value, Genesis)
@@ -201,10 +202,13 @@ func (bc *BlockChain) GetBlock(hash []byte) *Block {
func (self *BlockChain) GetBlockByNumber(num uint64) *Block {
block := self.CurrentBlock
- for ; block.Number.Uint64() != num; block = self.GetBlock(block.PrevHash) {
+ for ; block != nil; block = self.GetBlock(block.PrevHash) {
+ if block.Number.Uint64() == num {
+ break
+ }
}
- if block.Number.Uint64() == 0 && num != 0 {
+ if block != nil && block.Number.Uint64() == 0 && num != 0 {
return nil
}