GetBlock retrieves a block from the database by hash and number, caching it if found.
(hash common.Hash, number uint64)
| 710 | // GetBlock retrieves a block from the database by hash and number, |
| 711 | // caching it if found. |
| 712 | func (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. |
| 727 | func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block { |
no test coverage detected