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

Method GetBlock

core/blockchain.go:712–724  ·  view source on GitHub ↗

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

(hash common.Hash, number uint64)

Source from the content-addressed store, hash-verified

710// GetBlock retrieves a block from the database by hash and number,
711// caching it if found.
712func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
713 // Short circuit if the block's already in the cache, retrieve otherwise
714 if block, ok := bc.blockCache.Get(hash); ok {
715 return block.(*types.Block)
716 }
717 block := rawdb.ReadBlock(bc.db, hash, number)
718 if block == nil {
719 return nil
720 }
721 // Cache the found block for next time and return
722 bc.blockCache.Add(block.Hash(), block)
723 return block
724}
725
726// GetBlockByHash retrieves a block from the database by hash, caching it if found.
727func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {

Callers 10

SetHeadMethod · 0.95
repairMethod · 0.95
HasBlockAndStateMethod · 0.95
GetBlockByHashMethod · 0.95
GetBlockByNumberMethod · 0.95
GetBlocksFromHashMethod · 0.95
RollbackMethod · 0.95
ValidateBlockBodyMethod · 0.95
insertChainMethod · 0.95
reorgMethod · 0.95

Calls 3

GetMethod · 0.65
AddMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected