From 6bffa811d42cd26e57df734a808a728acaeb2956 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 16 Sep 2020 17:40:27 +0300 Subject: [PATCH] core: remove (*block.Block) checks for topBlock If it's non-nil, it has *block.Block inside. If it doesn't --- tell everyone about it with a nice panic message. --- pkg/core/blockchain.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 65055893d..01a48e92a 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -901,7 +901,8 @@ func (bc *Blockchain) GetStorageItems(id int32) (map[string]*state.StorageItem, func (bc *Blockchain) GetBlock(hash util.Uint256) (*block.Block, error) { topBlock := bc.topBlock.Load() if topBlock != nil { - if tb, ok := topBlock.(*block.Block); ok && tb.Hash().Equals(hash) { + tb := topBlock.(*block.Block) + if tb.Hash().Equals(hash) { return tb, nil } } @@ -924,7 +925,8 @@ func (bc *Blockchain) GetBlock(hash util.Uint256) (*block.Block, error) { func (bc *Blockchain) GetHeader(hash util.Uint256) (*block.Header, error) { topBlock := bc.topBlock.Load() if topBlock != nil { - if tb, ok := topBlock.(*block.Block); ok && tb.Hash().Equals(hash) { + tb := topBlock.(*block.Block) + if tb.Hash().Equals(hash) { return tb.Header(), nil } } @@ -954,9 +956,8 @@ func (bc *Blockchain) HasBlock(hash util.Uint256) bool { func (bc *Blockchain) CurrentBlockHash() util.Uint256 { topBlock := bc.topBlock.Load() if topBlock != nil { - if tb, ok := topBlock.(*block.Block); ok { - return tb.Hash() - } + tb := topBlock.(*block.Block) + return tb.Hash() } return bc.GetHeaderHash(int(bc.BlockHeight())) }