From 5ab59960ed07a4228e20569a1a252c9fc372191d Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 12 Aug 2021 14:17:33 +0530 Subject: [PATCH] add bor receipts --- ethclient/ethclient.go | 4 ++-- internal/ethapi/api.go | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 0f9bb295c2..40d66b6f72 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -78,8 +78,8 @@ func (ec *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo return ec.getBlock(ctx, "eth_getBlockByHash", hash, true) } -func (ec *Client) TransactionReceiptsInBlockByBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error) { - var rs []*types.Receipt +func (ec *Client) TransactionReceiptsInBlock(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]map[string]interface{}, error) { + var rs []map[string]interface{} err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlock", blockNrOrHash) if err != nil { return nil, err diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c759b307dc..a3e7b648fe 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -544,8 +544,21 @@ func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, } txs := block.Transactions() + + var txHash common.Hash + + borReceipt := rawdb.ReadBorReceipt(s.b.ChainDb(), block.Hash(), block.NumberU64()) + if borReceipt != nil { + receipts = append(receipts, borReceipt) + txHash = types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash())) + if txHash != (common.Hash{}) { + borTx, _, _, _, _ := s.b.GetBorBlockTransactionWithBlockHash(ctx, txHash, block.Hash()) + txs = append(txs, borTx) + } + } + if len(txs) != len(receipts) { - return nil, fmt.Errorf("txs length doesn't equal to receipts' length") + return nil, fmt.Errorf("txs length doesn't equal to receipts' length", len(txs), len(receipts)) } txReceipts := make([]map[string]interface{}, 0, len(txs)) @@ -581,11 +594,13 @@ func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, if receipt.Logs == nil { fields["logs"] = [][]*types.Log{} } + if borReceipt != nil { + fields["transactionHash"] = txHash + } // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation if receipt.ContractAddress != (common.Address{}) { fields["contractAddress"] = receipt.ContractAddress } - fields = s.appendRPCMarshalBorTransaction(ctx, block, fields, true) txReceipts = append(txReceipts, fields) }