@@ -86,6 +86,14 @@ func (bc *BlockChain) GetHeaderByNumber(number uint64) *types.Header {
8686 return bc .hc .GetHeaderByNumber (number )
8787}
8888
89+ // GetBlockNumber retrieves the block number associated with a block hash.
90+ func (bc * BlockChain ) GetBlockNumber (hash common.Hash ) * uint64 {
91+ if num , ok := bc .hc .GetBlockNumber (hash ); ok {
92+ return & num
93+ }
94+ return nil
95+ }
96+
8997// GetHeadersFrom returns a contiguous segment of headers, in rlp-form, going
9098// backwards from the given number.
9199func (bc * BlockChain ) GetHeadersFrom (number , count uint64 ) []rlp.RawValue {
@@ -99,11 +107,11 @@ func (bc *BlockChain) GetBody(hash common.Hash) *types.Body {
99107 if cached , ok := bc .bodyCache .Get (hash ); ok {
100108 return cached
101109 }
102- number := bc .hc .GetBlockNumber (hash )
103- if number == nil {
110+ number , ok := bc .hc .GetBlockNumber (hash )
111+ if ! ok {
104112 return nil
105113 }
106- body := rawdb .ReadBody (bc .db , hash , * number )
114+ body := rawdb .ReadBody (bc .db , hash , number )
107115 if body == nil {
108116 return nil
109117 }
@@ -119,11 +127,11 @@ func (bc *BlockChain) GetBodyRLP(hash common.Hash) rlp.RawValue {
119127 if cached , ok := bc .bodyRLPCache .Get (hash ); ok {
120128 return cached
121129 }
122- number := bc .hc .GetBlockNumber (hash )
123- if number == nil {
130+ number , ok := bc .hc .GetBlockNumber (hash )
131+ if ! ok {
124132 return nil
125133 }
126- body := rawdb .ReadBodyRLP (bc .db , hash , * number )
134+ body := rawdb .ReadBodyRLP (bc .db , hash , number )
127135 if len (body ) == 0 {
128136 return nil
129137 }
@@ -172,11 +180,11 @@ func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block {
172180
173181// GetBlockByHash retrieves a block from the database by hash, caching it if found.
174182func (bc * BlockChain ) GetBlockByHash (hash common.Hash ) * types.Block {
175- number := bc .hc .GetBlockNumber (hash )
176- if number == nil {
183+ number , ok := bc .hc .GetBlockNumber (hash )
184+ if ! ok {
177185 return nil
178186 }
179- return bc .GetBlock (hash , * number )
187+ return bc .GetBlock (hash , number )
180188}
181189
182190// GetBlockByNumber retrieves a block from the database by number, caching it
@@ -192,18 +200,18 @@ func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
192200// GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors.
193201// [deprecated by eth/62]
194202func (bc * BlockChain ) GetBlocksFromHash (hash common.Hash , n int ) (blocks []* types.Block ) {
195- number := bc .hc .GetBlockNumber (hash )
196- if number == nil {
203+ number , ok := bc .hc .GetBlockNumber (hash )
204+ if ! ok {
197205 return nil
198206 }
199207 for i := 0 ; i < n ; i ++ {
200- block := bc .GetBlock (hash , * number )
208+ block := bc .GetBlock (hash , number )
201209 if block == nil {
202210 break
203211 }
204212 blocks = append (blocks , block )
205213 hash = block .ParentHash ()
206- * number --
214+ number --
207215 }
208216 return
209217}
@@ -213,15 +221,15 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts {
213221 if receipts , ok := bc .receiptsCache .Get (hash ); ok {
214222 return receipts
215223 }
216- number := rawdb .ReadHeaderNumber (bc .db , hash )
217- if number == nil {
224+ number , ok := rawdb .ReadHeaderNumber (bc .db , hash )
225+ if ! ok {
218226 return nil
219227 }
220- header := bc .GetHeader (hash , * number )
228+ header := bc .GetHeader (hash , number )
221229 if header == nil {
222230 return nil
223231 }
224- receipts := rawdb .ReadReceipts (bc .db , hash , * number , header .Time , bc .chainConfig )
232+ receipts := rawdb .ReadReceipts (bc .db , hash , number , header .Time , bc .chainConfig )
225233 if receipts == nil {
226234 return nil
227235 }
@@ -230,11 +238,29 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts {
230238}
231239
232240func (bc * BlockChain ) GetRawReceiptsByHash (hash common.Hash ) types.Receipts {
233- number := rawdb .ReadHeaderNumber (bc .db , hash )
234- if number == nil {
241+ number , ok := rawdb .ReadHeaderNumber (bc .db , hash )
242+ if ! ok {
243+ return nil
244+ }
245+ return rawdb .ReadRawReceipts (bc .db , hash , number )
246+ }
247+
248+ // GetRawReceipts retrieves the receipts for all transactions in a given block
249+ // without deriving the internal fields and the Bloom.
250+ func (bc * BlockChain ) GetRawReceipts (hash common.Hash , number uint64 ) types.Receipts {
251+ if receipts , ok := bc .receiptsCache .Get (hash ); ok {
252+ return receipts
253+ }
254+ return rawdb .ReadRawReceipts (bc .db , hash , number )
255+ }
256+
257+ // GetReceiptsRLP retrieves the receipts of a block.
258+ func (bc * BlockChain ) GetReceiptsRLP (hash common.Hash ) rlp.RawValue {
259+ number , ok := rawdb .ReadHeaderNumber (bc .db , hash )
260+ if ! ok {
235261 return nil
236262 }
237- return rawdb .ReadRawReceipts (bc .db , hash , * number )
263+ return rawdb .ReadReceiptsRLP (bc .db , hash , number )
238264}
239265
240266// GetUnclesInChain retrieves all the uncles from a given block backwards until
0 commit comments