diff --git a/btcclient/query.go b/btcclient/query.go index 35c45f6..e6fb613 100644 --- a/btcclient/query.go +++ b/btcclient/query.go @@ -19,6 +19,10 @@ func (c *Client) GetBestBlock() (uint32, error) { return 0, err } + if height < 0 || height > int64(^uint32(0)) { + panic(fmt.Errorf("height (%d) is out of uint32 range", height)) //software bug, panic + } + return uint32(height), nil } @@ -34,7 +38,11 @@ func (c *Client) GetBlockByHash(blockHash *chainhash.Hash) (*types.IndexedBlock, } btcTxs := types.GetWrappedTxs(mBlock) - return types.NewIndexedBlock(uint32(blockInfo.Height), &mBlock.Header, btcTxs), mBlock, nil + height := blockInfo.Height + if height < 0 || height > int64(^uint32(0)) { + panic(fmt.Errorf("height (%d) is out of uint32 range", height)) //software bug, panic + } + return types.NewIndexedBlock(uint32(height), &mBlock.Header, btcTxs), mBlock, nil } // GetBlockByHeight returns a block with the given height