rpc: fix eth_getBlockByNumber (#78)

This commit is contained in:
Federico Kunze 2021-06-07 07:02:52 -04:00 committed by GitHub
parent 1ff3c46663
commit fcb7c114d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 27 deletions

View File

@ -137,44 +137,47 @@ func (e *EVMBackend) EthBlockFromTendermint(
txReceiptsResp, err := queryClient.TxReceiptsByBlockHeight(types.ContextWithHeight(block.Height), req) txReceiptsResp, err := queryClient.TxReceiptsByBlockHeight(types.ContextWithHeight(block.Height), req)
if err != nil { if err != nil {
e.logger.Debugf("TxReceiptsByBlockHeight fail: %s", err.Error()) e.logger.WithError(err).Debugln("TxReceiptsByBlockHeight failed")
return nil, err
} }
gasUsed := big.NewInt(0) gasUsed := big.NewInt(0)
ethRPCTxs := make([]interface{}, 0, len(txReceiptsResp.Receipts)) ethRPCTxs := []interface{}{}
for _, receipt := range txReceiptsResp.Receipts { if txReceiptsResp != nil {
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 { for _, receipt := range txReceiptsResp.Receipts {
e.logger.WithError(err).Warningf("NewTransactionFromData for receipt %s failed", hash) hash := common.HexToHash(receipt.Hash)
continue 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{}) blockBloomResp, err := queryClient.BlockBloom(types.ContextWithHeight(block.Height), &evmtypes.QueryBlockBloomRequest{})
if err != nil { if err != nil {
e.logger.WithError(err).Debugln("failed to query BlockBloom at height", block.Height) e.logger.WithError(err).Debugln("failed to query BlockBloom", "height", block.Height)
blockBloomResp.Bloom = ethtypes.Bloom{}.Bytes()
blockBloomResp = &evmtypes.QueryBlockBloomResponse{Bloom: ethtypes.Bloom{}.Bytes()}
} }
bloom := ethtypes.BytesToBloom(blockBloomResp.Bloom) bloom := ethtypes.BytesToBloom(blockBloomResp.Bloom)

View File

@ -199,7 +199,7 @@ func FormatBlock(
"receiptsRoot": ethtypes.EmptyRootHash, "receiptsRoot": ethtypes.EmptyRootHash,
"uncles": []common.Hash{}, "uncles": []common.Hash{},
"transactions": transactions.([]common.Hash), "transactions": transactions,
"totalDifficulty": (*hexutil.Big)(big.NewInt(0)), "totalDifficulty": (*hexutil.Big)(big.NewInt(0)),
} }
} }