Skip to content

Commit bd55ca1

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

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
@@ -405,10 +405,16 @@ func addContractAddress(table, query string, contractAddress string) string {
405405
}
406406

407407
func getTopicValueFormat(topic string) string {
408-
toAddressHex := ethereum.HexToAddress(topic)
409-
toAddressPadded := ethereum.LeftPadBytes(toAddressHex.Bytes(), 32)
410-
toAddressTopic := ethereum.BytesToHash(toAddressPadded).Hex()
411-
return toAddressTopic
408+
if topic == "" {
409+
// if there is no indexed topic, indexer stores an empty string
410+
// we shouldn't pad and hexify such an argument then
411+
return ""
412+
}
413+
asBytes := ethereum.FromHex(topic)
414+
// ensure the byte slice is exactly 32 bytes by left-padding with zeros
415+
asPadded := ethereum.LeftPadBytes(asBytes, 32)
416+
result := ethereum.BytesToHash(asPadded).Hex()
417+
return result
412418
}
413419

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

0 commit comments

Comments
 (0)