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

Method GetHeader

core/headerchain.go:344–356  ·  view source on GitHub ↗

GetHeader retrieves a block header from the database by hash and number, caching it if found.

(hash common.Hash, number uint64)

Source from the content-addressed store, hash-verified

342// GetHeader retrieves a block header from the database by hash and number,
343// caching it if found.
344func (hc *HeaderChain) GetHeader(hash common.Hash, number uint64) *types.Header {
345 // Short circuit if the header's already in the cache, retrieve otherwise
346 if header, ok := hc.headerCache.Get(hash); ok {
347 return header.(*types.Header)
348 }
349 header := rawdb.ReadHeader(hc.chainDb, hash, number)
350 if header == nil {
351 return nil
352 }
353 // Cache the found header for next time and return
354 hc.headerCache.Add(hash, header)
355 return header
356}
357
358// GetHeaderByHash retrieves a block header from the database by hash, caching it if
359// found.

Callers 5

GetAncestorMethod · 0.95
GetHeaderByHashMethod · 0.95
GetHeaderByNumberMethod · 0.95
SetHeadMethod · 0.95

Calls 2

GetMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected