GetBlockNumber retrieves the block number belonging to the given hash from the cache or database
(hash common.Hash)
| 135 | // GetBlockNumber retrieves the block number belonging to the given hash |
| 136 | // from the cache or database |
| 137 | func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64 { |
| 138 | if cached, ok := hc.numberCache.Get(hash); ok { |
| 139 | number := cached.(uint64) |
| 140 | return &number |
| 141 | } |
| 142 | number := rawdb.ReadHeaderNumber(hc.chainDb, hash) |
| 143 | if number != nil { |
| 144 | hc.numberCache.Add(hash, *number) |
| 145 | } |
| 146 | return number |
| 147 | } |
| 148 | |
| 149 | // WriteHeader writes a header into the local chain, given that its parent is |
| 150 | // already known. If the total difficulty of the newly inserted header becomes |
no test coverage detected