From 423beddf574383ec58246938f738f08cd50f031a Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 27 Jun 2014 00:16:49 +0200 Subject: [PATCH] nil check --- ethchain/block_chain.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ethchain/block_chain.go b/ethchain/block_chain.go index d0fea6641..6e4c72b27 100644 --- a/ethchain/block_chain.go +++ b/ethchain/block_chain.go @@ -221,9 +221,16 @@ func (bc *BlockChain) GetChainFromHash(hash []byte, max uint64) []interface{} { startNumber := parentNumber + count num := lastNumber - for ; num > startNumber; currentHash = bc.GetBlock(currentHash).PrevHash { + for num > startNumber { num-- + + block := bc.GetBlock(currentHash) + if block == nil { + break + } + currentHash = block.PrevHash } + for i := uint64(0); bytes.Compare(currentHash, hash) != 0 && num >= parentNumber && i < count; i++ { // Get the block of the chain block := bc.GetBlock(currentHash)