Skip to content

Commit fcb7c11

Browse files
authored
rpc: fix eth_getBlockByNumber (#78)
1 parent 1ff3c46 commit fcb7c11

2 files changed

Lines changed: 32 additions & 29 deletions

File tree

ethereum/rpc/backend.go

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -137,44 +137,47 @@ func (e *EVMBackend) EthBlockFromTendermint(
137137

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

144143
gasUsed := big.NewInt(0)
145144

146-
ethRPCTxs := make([]interface{}, 0, len(txReceiptsResp.Receipts))
147-
148-
for _, receipt := range txReceiptsResp.Receipts {
149-
hash := common.HexToHash(receipt.Hash)
150-
if fullTx {
151-
// full txs from receipts
152-
tx, err := types.NewTransactionFromData(
153-
receipt.Data,
154-
common.HexToAddress(receipt.From),
155-
hash,
156-
common.HexToHash(receipt.BlockHash),
157-
receipt.BlockHeight,
158-
receipt.Index,
159-
)
160-
161-
if err != nil {
162-
e.logger.WithError(err).Warningf("NewTransactionFromData for receipt %s failed", hash)
163-
continue
145+
ethRPCTxs := []interface{}{}
146+
147+
if txReceiptsResp != nil {
148+
149+
for _, receipt := range txReceiptsResp.Receipts {
150+
hash := common.HexToHash(receipt.Hash)
151+
if fullTx {
152+
// full txs from receipts
153+
tx, err := types.NewTransactionFromData(
154+
receipt.Data,
155+
common.HexToAddress(receipt.From),
156+
hash,
157+
common.HexToHash(receipt.BlockHash),
158+
receipt.BlockHeight,
159+
receipt.Index,
160+
)
161+
162+
if err != nil {
163+
e.logger.WithError(err).Warningf("NewTransactionFromData for receipt %s failed", hash)
164+
continue
165+
}
166+
167+
ethRPCTxs = append(ethRPCTxs, tx)
168+
gasUsed.Add(gasUsed, new(big.Int).SetUint64(receipt.Result.GasUsed))
169+
} else {
170+
// simply hashes
171+
ethRPCTxs = append(ethRPCTxs, hash)
164172
}
165-
166-
ethRPCTxs = append(ethRPCTxs, tx)
167-
gasUsed.Add(gasUsed, new(big.Int).SetUint64(receipt.Result.GasUsed))
168-
} else {
169-
// simply hashes
170-
ethRPCTxs = append(ethRPCTxs, hash)
171173
}
172174
}
173175

174176
blockBloomResp, err := queryClient.BlockBloom(types.ContextWithHeight(block.Height), &evmtypes.QueryBlockBloomRequest{})
175177
if err != nil {
176-
e.logger.WithError(err).Debugln("failed to query BlockBloom at height", block.Height)
177-
blockBloomResp.Bloom = ethtypes.Bloom{}.Bytes()
178+
e.logger.WithError(err).Debugln("failed to query BlockBloom", "height", block.Height)
179+
180+
blockBloomResp = &evmtypes.QueryBlockBloomResponse{Bloom: ethtypes.Bloom{}.Bytes()}
178181
}
179182

180183
bloom := ethtypes.BytesToBloom(blockBloomResp.Bloom)

ethereum/rpc/types/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func FormatBlock(
199199
"receiptsRoot": ethtypes.EmptyRootHash,
200200

201201
"uncles": []common.Hash{},
202-
"transactions": transactions.([]common.Hash),
202+
"transactions": transactions,
203203
"totalDifficulty": (*hexutil.Big)(big.NewInt(0)),
204204
}
205205
}

0 commit comments

Comments
 (0)