From 00ec4132f89527a6e2ae6b1d3842c447cab38cef Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Wed, 20 May 2015 06:41:50 +0200 Subject: [PATCH] Storing tx receipts in extraDb --- core/block_processor.go | 16 ++++++++++++++++ xeth/xeth.go | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/core/block_processor.go b/core/block_processor.go index 20e6722a4f..3a224059b9 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -23,6 +23,8 @@ const ( BlockChainVersion = 2 ) +var receiptsPre = []byte("receipts-") + type BlockProcessor struct { db common.Database extraDb common.Database @@ -262,9 +264,23 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st putTx(sm.extraDb, tx, block, uint64(i)) } + receiptsRlp := block.Receipts().RlpEncode() + sm.extraDb.Put(append(receiptsPre, block.Hash().Bytes()...), receiptsRlp) + return state.Logs(), nil } +func (self *BlockProcessor) GetBlockReceipts(bhash common.Hash) (receipts types.Receipts, err error) { + var rdata []byte + rdata, err = self.extraDb.Get(append(receiptsPre, bhash[:]...)) + + if err == nil { + err = rlp.DecodeBytes(rdata, &receipts) + } + return + +} + // Validates the current block. Returns an error if the block was invalid, // an uncle or anything that isn't on the current block chain. // Validation validates easy over difficult (dagger takes longer time = difficult) diff --git a/xeth/xeth.go b/xeth/xeth.go index 7de3e31be4..3772146de6 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -350,6 +350,24 @@ func (self *XEth) CurrentBlock() *types.Block { return self.backend.ChainManager().CurrentBlock() } +func (self *XEth) GetBlockReceipts(bhash common.Hash) (receipts types.Receipts, err error) { + return self.backend.BlockProcessor().GetBlockReceipts(bhash) +} + +func (self *XEth) GetTxReceipt(txhash common.Hash) (receipt *types.Receipt, err error) { + _, bhash, _, txi := self.EthTransactionByHash(common.ToHex(txhash[:])) + var receipts types.Receipts + receipts, err = self.backend.BlockProcessor().GetBlockReceipts(bhash) + if err == nil { + if txi < uint64(len(receipts)) { + receipt = receipts[txi] + } else { + err = fmt.Errorf("Invalid tx index") + } + } + return +} + func (self *XEth) GasLimit() *big.Int { return self.backend.ChainManager().GasLimit() }