|
|
|
@ -126,15 +126,48 @@ func GetBlock(ctx context.Context, odr OdrBackend, hash common.Hash, number uint |
|
|
|
|
// GetBlockReceipts retrieves the receipts generated by the transactions included
|
|
|
|
|
// in a block given by its hash.
|
|
|
|
|
func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (types.Receipts, error) { |
|
|
|
|
// Retrieve the potentially incomplete receipts from disk or network
|
|
|
|
|
receipts := core.GetBlockReceipts(odr.Database(), hash, number) |
|
|
|
|
if receipts != nil { |
|
|
|
|
return receipts, nil |
|
|
|
|
if receipts == nil { |
|
|
|
|
r := &ReceiptsRequest{Hash: hash, Number: number} |
|
|
|
|
if err := odr.Retrieve(ctx, r); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
receipts = r.Receipts |
|
|
|
|
} |
|
|
|
|
// If the receipts are incomplete, fill the derived fields
|
|
|
|
|
if len(receipts) > 0 && receipts[0].TxHash == (common.Hash{}) { |
|
|
|
|
block, err := GetBlock(ctx, odr, hash, number) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
genesis := core.GetCanonicalHash(odr.Database(), 0) |
|
|
|
|
config, _ := core.GetChainConfig(odr.Database(), genesis) |
|
|
|
|
|
|
|
|
|
core.SetReceiptsData(config, block, receipts) |
|
|
|
|
core.WriteBlockReceipts(odr.Database(), hash, number, receipts) |
|
|
|
|
} |
|
|
|
|
return receipts, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetBlockLogs retrieves the logs generated by the transactions included in a
|
|
|
|
|
// block given by its hash.
|
|
|
|
|
func GetBlockLogs(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) ([][]*types.Log, error) { |
|
|
|
|
// Retrieve the potentially incomplete receipts from disk or network
|
|
|
|
|
receipts := core.GetBlockReceipts(odr.Database(), hash, number) |
|
|
|
|
if receipts == nil { |
|
|
|
|
r := &ReceiptsRequest{Hash: hash, Number: number} |
|
|
|
|
if err := odr.Retrieve(ctx, r); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
return r.Receipts, nil |
|
|
|
|
receipts = r.Receipts |
|
|
|
|
} |
|
|
|
|
// Return the logs without deriving any computed fields on the receipts
|
|
|
|
|
logs := make([][]*types.Log, len(receipts)) |
|
|
|
|
for i, receipt := range receipts { |
|
|
|
|
logs[i] = receipt.Logs |
|
|
|
|
} |
|
|
|
|
return logs, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetBloomBits retrieves a batch of compressed bloomBits vectors belonging to the given bit index and section indexes
|
|
|
|
|