@@ -18,6 +18,7 @@ import (
1818 zLog "github.com/rs/zerolog/log"
1919 config "github.com/thirdweb-dev/indexer/configs"
2020 "github.com/thirdweb-dev/indexer/internal/common"
21+ "github.com/thirdweb-dev/indexer/internal/rpc"
2122)
2223
2324type ClickHouseConnector struct {
@@ -339,7 +340,7 @@ func (c *ClickHouseConnector) GetBlocks(qf QueryFilter) (blocks []common.Block,
339340}
340341
341342func (c * ClickHouseConnector ) GetTransactions (qf QueryFilter ) (QueryResult [common.Transaction ], error ) {
342- columns := "chain_id, hash, nonce, block_hash, block_number, block_timestamp, transaction_index, from_address, to_address, value, gas, gas_price, data, max_fee_per_gas, max_priority_fee_per_gas, transaction_type, r, s, v, access_list"
343+ columns := "chain_id, hash, nonce, block_hash, block_number, block_timestamp, transaction_index, from_address, to_address, value, gas, gas_price, data, function_selector, max_fee_per_gas, max_priority_fee_per_gas, transaction_type, r, s, v, access_list"
343344 return executeQuery [common.Transaction ](c , "transactions" , columns , qf , scanTransaction )
344345}
345346
@@ -359,7 +360,7 @@ func (c *ClickHouseConnector) GetAggregations(table string, qf QueryFilter) (Que
359360 }
360361 query = addContractAddress (table , query , qf .ContractAddress )
361362 if qf .Signature != "" {
362- query += fmt . Sprintf ( " AND topic_0 = '%s'" , qf .Signature )
363+ query = addSignatureClause ( table , query , qf .Signature )
363364 }
364365 for key , value := range qf .FilterParams {
365366 query = addFilterParams (key , strings .ToLower (value ), query )
@@ -452,7 +453,7 @@ func (c *ClickHouseConnector) buildQuery(table, columns string, qf QueryFilter)
452453
453454 // Add signature clause
454455 if qf .Signature != "" {
455- query += fmt . Sprintf ( " AND topic_0 = '%s'" , qf .Signature )
456+ query = addSignatureClause ( table , query , qf .Signature )
456457 }
457458 // Add filter params
458459 for key , value := range qf .FilterParams {
@@ -516,6 +517,15 @@ func addContractAddress(table, query string, contractAddress string) string {
516517 return query
517518}
518519
520+ func addSignatureClause (table , query , signature string ) string {
521+ if table == "logs" {
522+ query += fmt .Sprintf (" AND topic_0 = '%s'" , signature )
523+ } else if table == "transactions" {
524+ query += fmt .Sprintf (" AND function_selector = '%s'" , rpc .ExtractFunctionSelector (signature ))
525+ }
526+ return query
527+ }
528+
519529func getTopicValueFormat (topic string ) string {
520530 if topic == "" {
521531 // if there is no indexed topic, indexer stores an empty string
@@ -545,6 +555,7 @@ func scanTransaction(rows driver.Rows) (common.Transaction, error) {
545555 & tx .Gas ,
546556 & tx .GasPrice ,
547557 & tx .Data ,
558+ & tx .FunctionSelector ,
548559 & tx .MaxFeePerGas ,
549560 & tx .MaxPriorityFeePerGas ,
550561 & tx .TransactionType ,
0 commit comments