X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=protocol%2Fblock.go;fp=protocol%2Fblock.go;h=d5ef5cf7e031eff6cfd4c799d71beb802923e071;hb=5e8fb58293815103f117402919045e64836d423a;hp=8d87804234cb4f59996b851ab3b5d222de5c2a43;hpb=f47413c46121216dae3b1a905fbe53ae559adee2;p=bytom%2Fvapor.git diff --git a/protocol/block.go b/protocol/block.go index 8d878042..d5ef5cf7 100644 --- a/protocol/block.go +++ b/protocol/block.go @@ -28,7 +28,11 @@ func (c *Chain) BlockExist(hash *bc.Hash) bool { // 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 @@ -37,7 +41,7 @@ func (c *Chain) GetBlockByHeight(height uint64) (*types.Block, error) { 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 @@ -125,7 +129,7 @@ func (c *Chain) reorganizeChain(node *state.BlockNode) error { } 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 } @@ -152,7 +156,7 @@ func (c *Chain) reorganizeChain(node *state.BlockNode) error { } 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 }