Merge pull request #279 from cerc-io/ian_updates
rawdb helper functions
This commit is contained in:
commit
c9beb11f8f
@ -644,6 +644,23 @@ func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, config *para
|
||||
return receipts
|
||||
}
|
||||
|
||||
// ReadStorageReceipts is a modification of ReadRawReceipts that skips a conversion to types.Receipt
|
||||
// and returns the ReceipstForStorage instead
|
||||
func ReadStorageReceipts(db ethdb.Reader, hash common.Hash, number uint64) []*types.ReceiptForStorage {
|
||||
// Retrieve the flattened receipt slice
|
||||
data := ReadReceiptsRLP(db, hash, number)
|
||||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
// Convert the receipts from their storage form to their internal representation
|
||||
var storageReceipts []*types.ReceiptForStorage
|
||||
if err := rlp.DecodeBytes(data, &storageReceipts); err != nil {
|
||||
log.Error("Invalid receipt array RLP", "hash", hash, "err", err)
|
||||
return nil
|
||||
}
|
||||
return storageReceipts
|
||||
}
|
||||
|
||||
// WriteReceipts stores all the transaction receipts belonging to a block.
|
||||
func WriteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64, receipts types.Receipts) {
|
||||
// Convert the receipts into their storage form and serialize them
|
||||
@ -817,6 +834,17 @@ func WriteAncientBlocks(db ethdb.AncientWriter, blocks []*types.Block, receipts
|
||||
})
|
||||
}
|
||||
|
||||
// WriteAncientBlock is a public wrapper of writeAncientBlock
|
||||
func WriteAncientBlock(op ethdb.AncientWriteOp, block *types.Block, receipts types.Receipts, td *big.Int) error {
|
||||
stReceipts := make([]*types.ReceiptForStorage, len(receipts))
|
||||
// Convert receipts to storage format and sum up total difficulty.
|
||||
stReceipts = stReceipts[:0]
|
||||
for i, receipt := range receipts {
|
||||
stReceipts[i] = (*types.ReceiptForStorage)(receipt)
|
||||
}
|
||||
return writeAncientBlock(op, block, block.Header(), stReceipts, td)
|
||||
}
|
||||
|
||||
func writeAncientBlock(op ethdb.AncientWriteOp, block *types.Block, header *types.Header, receipts []*types.ReceiptForStorage, td *big.Int) error {
|
||||
num := block.NumberU64()
|
||||
if err := op.AppendRaw(chainFreezerHashTable, num, block.Hash().Bytes()); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user