// GetBlockByHash return a block by given hash
func (c *Chain) GetBlockByHash(hash *bc.Hash) (*types.Block, error) {
- return c.store.GetBlock(hash)
+ node := c.index.GetNode(hash)
+ if node == nil {
+ return nil, errors.New("can't find block in given hash")
+ }
+ return c.store.GetBlock(hash, node.Height)
}
// GetBlockByHeight return a block header by given height
if node == nil {
return nil, errors.New("can't find block in given height")
}
- return c.store.GetBlock(&node.Hash)
+ return c.store.GetBlock(&node.Hash, height)
}
// GetHeaderByHash return a block header by given hash
}
for _, detachNode := range detachNodes {
- b, err := c.store.GetBlock(&detachNode.Hash)
+ b, err := c.store.GetBlock(&detachNode.Hash, detachNode.Height)
if err != nil {
return err
}
}
for _, attachNode := range attachNodes {
- b, err := c.store.GetBlock(&attachNode.Hash)
+ b, err := c.store.GetBlock(&attachNode.Hash, attachNode.Height)
if err != nil {
return err
}