From bd55ca161980afebe0fd8064f246d32bdbab1757 Mon Sep 17 00:00:00 2001 From: catalyst17 <37663786+catalyst17@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:32:58 +0200 Subject: [PATCH] fix: don't cut bytes from non-address topics + account for empty topics --- internal/storage/clickhouse.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/storage/clickhouse.go b/internal/storage/clickhouse.go index 6f5f187..0abf208 100644 --- a/internal/storage/clickhouse.go +++ b/internal/storage/clickhouse.go @@ -405,10 +405,16 @@ func addContractAddress(table, query string, contractAddress string) string { } func getTopicValueFormat(topic string) string { - toAddressHex := ethereum.HexToAddress(topic) - toAddressPadded := ethereum.LeftPadBytes(toAddressHex.Bytes(), 32) - toAddressTopic := ethereum.BytesToHash(toAddressPadded).Hex() - return toAddressTopic + if topic == "" { + // if there is no indexed topic, indexer stores an empty string + // we shouldn't pad and hexify such an argument then + return "" + } + asBytes := ethereum.FromHex(topic) + // ensure the byte slice is exactly 32 bytes by left-padding with zeros + asPadded := ethereum.LeftPadBytes(asBytes, 32) + result := ethereum.BytesToHash(asPadded).Hex() + return result } func (c *ClickHouseConnector) executeAggregateQuery(table string, qf QueryFilter) (map[string]string, error) {