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

Method fetchBlockByHeight

blockproducer/chain_io.go:54–71  ·  view source on GitHub ↗
(h uint32)

Source from the content-addressed store, hash-verified

52}
53
54func (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
73func (c *Chain) fetchBlockByCount(count uint32) (b *types.BPBlock, height uint32, err error) {
74 var node = c.head().ancestorByCount(count)

Callers 2

TestChainFunction · 0.80
FetchBlockMethod · 0.80

Calls 4

headMethod · 0.95
loadBlockMethod · 0.95
ancestorMethod · 0.45
loadMethod · 0.45

Tested by 1

TestChainFunction · 0.64