FetchBlockByCount fetches the block at specified count from local cache.
(count int32)
| 888 | |
| 889 | // FetchBlockByCount fetches the block at specified count from local cache. |
| 890 | func (c *Chain) FetchBlockByCount(count int32) (b *types.Block, realCount int32, height int32, err error) { |
| 891 | var n *blockNode |
| 892 | |
| 893 | if count < 0 { |
| 894 | n = c.rt.getHead().node |
| 895 | } else { |
| 896 | n = c.rt.getHead().node.ancestorByCount(count) |
| 897 | } |
| 898 | |
| 899 | if n != nil { |
| 900 | b, err = c.fetchBlockByIndexKey(n.indexKey()) |
| 901 | if err != nil { |
| 902 | return |
| 903 | } |
| 904 | |
| 905 | height = n.height |
| 906 | realCount = n.count |
| 907 | } |
| 908 | |
| 909 | return |
| 910 | } |
| 911 | |
| 912 | func (c *Chain) fetchBlockByIndexKey(indexKey []byte) (b *types.Block, err error) { |
| 913 | k := utils.ConcatAll(c.metaBlockIndex, indexKey) |
nothing calls this directly
no test coverage detected