Skip to content

Commit

Permalink
fix: indexer: Reduce number of toHex conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Dec 22, 2023
1 parent 41840a3 commit 26b790c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions indexer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ func blockToModels(
bshash := block.Header.StateRoot.Hex()
logsBloom := ethtypes.BytesToBloom(ethtypes.LogsBloom(logs))
bloomData, _ := logsBloom.MarshalText()
bloomHex := hex.EncodeToString(bloomData)
baseFee := big.NewInt(10)
number := big.NewInt(0)
number.SetUint64(block.Header.Round)
var btxHash string
if len(transactions) == 0 {
btxHash = ethtypes.EmptyRootHash.Hex()
Expand All @@ -123,7 +122,7 @@ func blockToModels(
ReceiptHash: ethtypes.EmptyRootHash.Hex(),
Bloom: string(bloomData),
Difficulty: big.NewInt(0).String(),
Number: number.Uint64(),
Number: block.Header.Round,
GasLimit: blockGasLimit,
Time: uint64(block.Header.Timestamp),
Extra: "",
Expand All @@ -136,6 +135,7 @@ func blockToModels(
innerReceipts := make([]*model.Receipt, 0, len(transactions))
cumulativeGasUsed := uint64(0)
for idx, ethTx := range transactions {
ethTxHex := ethTx.Hash().Hex()
v, r, s := ethTx.RawSignatureValues()
signer := ethtypes.LatestSignerForChainID(ethTx.ChainId())
from, _ := signer.Sender(ethTx)
Expand All @@ -153,12 +153,12 @@ func blockToModels(
accList = append(accList, acc)
}
tx := &model.Transaction{
Hash: ethTx.Hash().Hex(),
Hash: ethTxHex,
Type: ethTx.Type(),
ChainID: ethTx.ChainId().String(),
Status: uint(txsStatus[idx]),
BlockHash: bhash,
Round: number.Uint64(),
Round: block.Header.Round,
Index: uint32(idx),
Gas: ethTx.Gas(),
GasPrice: ethTx.GasPrice().String(),
Expand Down Expand Up @@ -186,9 +186,9 @@ func blockToModels(
receipt := &model.Receipt{
Status: uint(txsStatus[idx]),
CumulativeGasUsed: cumulativeGasUsed,
Logs: txLogs[ethTx.Hash().Hex()],
LogsBloom: hex.EncodeToString(bloomData),
TransactionHash: ethTx.Hash().Hex(),
Logs: txLogs[ethTxHex],
LogsBloom: bloomHex,
TransactionHash: ethTxHex,
BlockHash: bhash,
GasUsed: txsGasUsed[idx],
Type: uint(ethTx.Type()),
Expand All @@ -213,7 +213,7 @@ func blockToModels(

innerBlock := &model.Block{
Hash: bhash,
Round: number.Uint64(),
Round: block.Header.Round,
Header: innerHeader,
Transactions: innerTxs,
}
Expand Down

0 comments on commit 26b790c

Please sign in to comment.