Skip to content

Commit 423bedd

Browse files
committed
nil check
1 parent 8119d77 commit 423bedd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ethchain/block_chain.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,16 @@ func (bc *BlockChain) GetChainFromHash(hash []byte, max uint64) []interface{} {
221221
startNumber := parentNumber + count
222222

223223
num := lastNumber
224-
for ; num > startNumber; currentHash = bc.GetBlock(currentHash).PrevHash {
224+
for num > startNumber {
225225
num--
226+
227+
block := bc.GetBlock(currentHash)
228+
if block == nil {
229+
break
230+
}
231+
currentHash = block.PrevHash
226232
}
233+
227234
for i := uint64(0); bytes.Compare(currentHash, hash) != 0 && num >= parentNumber && i < count; i++ {
228235
// Get the block of the chain
229236
block := bc.GetBlock(currentHash)

0 commit comments

Comments
 (0)