Skip to content

Commit

Permalink
fix: don't cut bytes from non-address topics + account for empty topics
Browse files Browse the repository at this point in the history
  • Loading branch information
catalyst17 committed Oct 18, 2024
1 parent b0a4ef9 commit bd55ca1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/storage/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bd55ca1

Please sign in to comment.