Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
rpc: fix eth_getBlockByNumber (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze authored Jun 7, 2021
1 parent 1ff3c46 commit fcb7c11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
59 changes: 31 additions & 28 deletions ethereum/rpc/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,44 +137,47 @@ func (e *EVMBackend) EthBlockFromTendermint(

txReceiptsResp, err := queryClient.TxReceiptsByBlockHeight(types.ContextWithHeight(block.Height), req)
if err != nil {
e.logger.Debugf("TxReceiptsByBlockHeight fail: %s", err.Error())
return nil, err
e.logger.WithError(err).Debugln("TxReceiptsByBlockHeight failed")
}

gasUsed := big.NewInt(0)

ethRPCTxs := make([]interface{}, 0, len(txReceiptsResp.Receipts))

for _, receipt := range txReceiptsResp.Receipts {
hash := common.HexToHash(receipt.Hash)
if fullTx {
// full txs from receipts
tx, err := types.NewTransactionFromData(
receipt.Data,
common.HexToAddress(receipt.From),
hash,
common.HexToHash(receipt.BlockHash),
receipt.BlockHeight,
receipt.Index,
)

if err != nil {
e.logger.WithError(err).Warningf("NewTransactionFromData for receipt %s failed", hash)
continue
ethRPCTxs := []interface{}{}

if txReceiptsResp != nil {

for _, receipt := range txReceiptsResp.Receipts {
hash := common.HexToHash(receipt.Hash)
if fullTx {
// full txs from receipts
tx, err := types.NewTransactionFromData(
receipt.Data,
common.HexToAddress(receipt.From),
hash,
common.HexToHash(receipt.BlockHash),
receipt.BlockHeight,
receipt.Index,
)

if err != nil {
e.logger.WithError(err).Warningf("NewTransactionFromData for receipt %s failed", hash)
continue
}

ethRPCTxs = append(ethRPCTxs, tx)
gasUsed.Add(gasUsed, new(big.Int).SetUint64(receipt.Result.GasUsed))
} else {
// simply hashes
ethRPCTxs = append(ethRPCTxs, hash)
}

ethRPCTxs = append(ethRPCTxs, tx)
gasUsed.Add(gasUsed, new(big.Int).SetUint64(receipt.Result.GasUsed))
} else {
// simply hashes
ethRPCTxs = append(ethRPCTxs, hash)
}
}

blockBloomResp, err := queryClient.BlockBloom(types.ContextWithHeight(block.Height), &evmtypes.QueryBlockBloomRequest{})
if err != nil {
e.logger.WithError(err).Debugln("failed to query BlockBloom at height", block.Height)
blockBloomResp.Bloom = ethtypes.Bloom{}.Bytes()
e.logger.WithError(err).Debugln("failed to query BlockBloom", "height", block.Height)

blockBloomResp = &evmtypes.QueryBlockBloomResponse{Bloom: ethtypes.Bloom{}.Bytes()}
}

bloom := ethtypes.BytesToBloom(blockBloomResp.Bloom)
Expand Down
2 changes: 1 addition & 1 deletion ethereum/rpc/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func FormatBlock(
"receiptsRoot": ethtypes.EmptyRootHash,

"uncles": []common.Hash{},
"transactions": transactions.([]common.Hash),
"transactions": transactions,
"totalDifficulty": (*hexutil.Big)(big.NewInt(0)),
}
}
Expand Down

0 comments on commit fcb7c11

Please sign in to comment.