| 52 | } |
| 53 | |
| 54 | func (c *Chain) fetchBlockByHeight(h uint32) (b *types.BPBlock, count uint32, err error) { |
| 55 | var node = c.head().ancestor(h) |
| 56 | // Not found |
| 57 | if node == nil { |
| 58 | return |
| 59 | } |
| 60 | // OK, and block is cached |
| 61 | if b = node.load(); b != nil { |
| 62 | count = node.count |
| 63 | return |
| 64 | } |
| 65 | // Not cached, read from database |
| 66 | if b, err = c.loadBlock(node.hash); err != nil { |
| 67 | return |
| 68 | } |
| 69 | count = node.count |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | func (c *Chain) fetchBlockByCount(count uint32) (b *types.BPBlock, height uint32, err error) { |
| 74 | var node = c.head().ancestorByCount(count) |