MCPcopy Create free account
hub / github.com/CPChain/chain / GetBlockHashesFromHash

Method GetBlockHashesFromHash

core/headerchain.go:284–303  ·  view source on GitHub ↗

GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.

(hash common.Hash, max uint64)

Source from the content-addressed store, hash-verified

282// GetBlockHashesFromHash retrieves a number of block hashes starting at a given
283// hash, fetching towards the genesis block.
284func (hc *HeaderChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash {
285 // Get the origin header from which to fetch
286 header := hc.GetHeaderByHash(hash)
287 if header == nil {
288 return nil
289 }
290 // Iterate the headers until enough is collected or the genesis reached
291 chain := make([]common.Hash, 0, max)
292 for i := uint64(0); i < max; i++ {
293 next := header.ParentHash
294 if header = hc.GetHeader(next, header.Number.Uint64()-1); header == nil {
295 break
296 }
297 chain = append(chain, next)
298 if header.Number.Sign() == 0 {
299 break
300 }
301 }
302 return chain
303}
304
305// GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or
306// a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the

Callers

nothing calls this directly

Calls 4

GetHeaderByHashMethod · 0.95
GetHeaderMethod · 0.95
Uint64Method · 0.80
SignMethod · 0.45

Tested by

no test coverage detected