MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / FetchBlockByCount

Method FetchBlockByCount

sqlchain/chain.go:890–910  ·  view source on GitHub ↗

FetchBlockByCount fetches the block at specified count from local cache.

(count int32)

Source from the content-addressed store, hash-verified

888
889// FetchBlockByCount fetches the block at specified count from local cache.
890func (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
912func (c *Chain) fetchBlockByIndexKey(indexKey []byte) (b *types.Block, err error) {
913 k := utils.ConcatAll(c.metaBlockIndex, indexKey)

Callers

nothing calls this directly

Calls 4

fetchBlockByIndexKeyMethod · 0.95
indexKeyMethod · 0.95
getHeadMethod · 0.45
ancestorByCountMethod · 0.45

Tested by

no test coverage detected