Skip to content

Commit a55695d

Browse files
committed
fix: don't cut bytes from non-address topics + account for empty topics
1 parent c6fc50e commit a55695d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

internal/storage/clickhouse.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,16 @@ func addContractAddress(table, query string, contractAddress string) string {
456456
}
457457

458458
func getTopicValueFormat(topic string) string {
459-
toAddressHex := ethereum.HexToAddress(topic)
460-
toAddressPadded := ethereum.LeftPadBytes(toAddressHex.Bytes(), 32)
461-
toAddressTopic := ethereum.BytesToHash(toAddressPadded).Hex()
462-
return toAddressTopic
459+
if topic == "" {
460+
// if there is no indexed topic, indexer stores an empty string
461+
// we shouldn't pad and hexify such an argument then
462+
return ""
463+
}
464+
asBytes := ethereum.FromHex(topic)
465+
// ensure the byte slice is exactly 32 bytes by left-padding with zeros
466+
asPadded := ethereum.LeftPadBytes(asBytes, 32)
467+
result := ethereum.BytesToHash(asPadded).Hex()
468+
return result
463469
}
464470

465471
func (c *ClickHouseConnector) executeAggregateQuery(table string, qf QueryFilter) (map[string]string, error) {

0 commit comments

Comments
 (0)