Skip to content

Commit

Permalink
Added just in time encoding for events signatures (#57)
Browse files Browse the repository at this point in the history
### TL;DR

Updated API structure and query handling for improved contract and signature-based queries.

### What changed?

- Modified `Meta` struct to use `*uint64` for `ChainIdentifier`
- Updated `GetChainId` function to return `*uint64` instead of string
- Renamed route parameters for better clarity (e.g., `contractAddress` to `to`)
- Implemented signature hashing for event and function signatures
- Updated query filters to use `ToAddress` instead of `ContractAddress`
- Added support for querying logs by padded `to_address` in topic_2
- Adjusted query building logic to handle different tables (logs and transactions)

### How to test?

1. Test API endpoints with updated route parameters:
   - `/api/v1/{chainId}/transactions/{to}`
   - `/api/v1/{chainId}/events/{to}`
   - `/api/v1/{chainId}/transactions/{to}/{signature}`
   - `/api/v1/{chainId}/events/{to}/{signature}`

2. Verify that queries work correctly with the new `ToAddress` filter
3. Check that signature hashing is applied correctly for event and function signatures
4. Ensure that logs queries correctly filter by the padded `to_address` in topic_2

### Why make this change?

These changes improve the API's flexibility and accuracy when querying contract-specific data. By using more precise parameter names and implementing proper signature hashing, the API can provide more reliable and targeted results. The updates also enhance the ability to filter logs by the correct `to_address` format, ensuring better compatibility with Ethereum event structures.
  • Loading branch information
AmineAfia authored Sep 30, 2024
1 parent 5a231b3 commit ce8c111
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 55 deletions.
33 changes: 17 additions & 16 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ type QueryParams struct {
SortOrder string `schema:"sort_order"`
Page int `schema:"page"`
Limit int `schema:"limit"`
Aggregates []string `schema:"aggregate"`
Aggregates []string `schema:"aggregate"`
}

type Meta struct {
ChainIdentifier string `json:"chain_identifier"`
ContractAddress string `json:"contract_address"`
Signature string `json:"signature"`
Page int `json:"page"`
Limit int `json:"limit"`
TotalItems int `json:"total_items"`
TotalPages int `json:"total_pages"`
ChainIdentifier *uint64 `json:"chain_identifier"`
ContractAddress string `json:"contract_address"`
Signature string `json:"signature"`
Page int `json:"page"`
Limit int `json:"limit"`
TotalItems int `json:"total_items"`
TotalPages int `json:"total_pages"`
}

type QueryResponse struct {
Meta Meta `json:"meta"`
Data interface{} `json:"data,omitempty"`
Aggregations map[string]string `json:"aggregations,omitempty"`
Meta Meta `json:"meta"`
Data interface{} `json:"data,omitempty"`
Aggregations map[string]string `json:"aggregations,omitempty"`
}

func writeError(w http.ResponseWriter, message string, code int) {
Expand Down Expand Up @@ -97,12 +97,13 @@ func ParseQueryParams(r *http.Request) (QueryParams, error) {
return params, nil
}

func GetChainId(r *http.Request) (string, error) {
func GetChainId(r *http.Request) (*uint64, error) {
// TODO: check chainId agains the chain-service to ensure it's valid
chainId := chi.URLParam(r, "chainId")
if _, err := strconv.Atoi(chainId); err != nil {
log.Error().Err(err).Msg("Error getting chainId")
return "", err
chainIdInt, err := strconv.ParseUint(chainId, 10, 64)
if err != nil {
log.Error().Err(err).Msg("Error parsing chainId")
return nil, err
}
return chainId, nil
return &chainIdInt, nil
}
7 changes: 6 additions & 1 deletion cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

"github.com/go-chi/chi/middleware"
"github.com/go-chi/chi/v5"
"github.com/thirdweb-dev/indexer/internal/handlers"
)
Expand All @@ -23,10 +24,14 @@ var (

func RunApi(cmd *cobra.Command, args []string) {
var r *chi.Mux = chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Use(middleware.RequestID)

handlers.Handler(r)

log.Info().Msg("Starting Server on port 3000")
err := http.ListenAndServe("localhost:3000", r)
err := http.ListenAndServe(":3000", r)
if err != nil {
log.Error().Err(err).Msg("Error starting server")
}
Expand Down
13 changes: 5 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module github.com/thirdweb-dev/indexer

go 1.22.0
go 1.23

require (
github.com/ClickHouse/clickhouse-go/v2 v2.28.3
github.com/ethereum/go-ethereum v1.14.8
github.com/go-chi/chi v1.5.5
github.com/go-chi/chi/v5 v5.1.0
github.com/google/uuid v1.6.0
github.com/go-redis/redis/v8 v8.11.5
github.com/gorilla/schema v1.4.1
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/joho/godotenv v1.5.1
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.18.0
)

require (
Expand All @@ -24,7 +25,6 @@ require (
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand All @@ -33,7 +33,7 @@ require (
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
Expand All @@ -48,7 +48,6 @@ require (
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
Expand All @@ -57,9 +56,7 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
Expand Down
18 changes: 12 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH
github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M=
github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c h1:uQYC5Z1mdLRPrZhHjHxufI8+2UG/i25QG92j0Er9p6I=
Expand All @@ -63,6 +61,8 @@ github.com/ethereum/go-ethereum v1.14.8 h1:NgOWvXS+lauK+zFukEvi85UmmsS/OkV0N23UZ
github.com/ethereum/go-ethereum v1.14.8/go.mod h1:TJhyuDq0JDppAkFXgqjwpdlQApywnu/m10kFPxh8vvs=
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4=
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI=
Expand Down Expand Up @@ -124,8 +124,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
Expand Down Expand Up @@ -162,8 +160,14 @@ github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iP
github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU=
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/paulmach/orb v0.11.1 h1:3koVegMC4X/WeiXYz9iswopaTwMem53NzTJuTF20JzU=
github.com/paulmach/orb v0.11.1/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU=
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
Expand Down Expand Up @@ -217,8 +221,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.0 h1:pN6W1ub/G4OfnM+NR9p7xP9R6TltLUzp5JG9yZD3Qg0=
github.com/spf13/viper v1.18.0/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down Expand Up @@ -278,6 +280,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -328,6 +332,8 @@ gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
10 changes: 5 additions & 5 deletions internal/handlers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (

func Handler(r *chi.Mux) {
r.Use(chimiddle.StripSlashes)
r.Use(middleware.Authorization)
r.Route("/", func(router chi.Router) {
router.Use(middleware.Authorization)
// might consolidate all variants to one handler function
// Wild card queries
router.Get("/{chainId}/transactions", GetTransactions)
router.Get("/{chainId}/events", GetLogs)

// contract scoped queries
router.Get("/{chainId}/transactions/{contractAddress}", GetTransactionsByContract)
router.Get("/{chainId}/events/{contractAddress}", GetLogsByContract)
router.Get("/{chainId}/transactions/{to}", GetTransactionsByContract)
router.Get("/{chainId}/events/{contract}", GetLogsByContract)

// signature scoped queries
router.Get("/{chainId}/transactions/{contractAddress}/{functionSig}", GetTransactionsByContractAndSignature)
router.Get("/{chainId}/events/{contractAddress}/{eventSig}", GetLogsByContractAndSignature)
router.Get("/{chainId}/transactions/{to}/{signature}", GetTransactionsByContractAndSignature)
router.Get("/{chainId}/events/{contract}/{signature}", GetLogsByContractAndSignature)
})

r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
Expand Down
20 changes: 13 additions & 7 deletions internal/handlers/logs_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"sync"

"github.com/ethereum/go-ethereum/crypto"
"github.com/go-chi/chi/v5"
"github.com/rs/zerolog/log"
"github.com/thirdweb-dev/indexer/api"
Expand All @@ -24,14 +25,14 @@ func GetLogs(w http.ResponseWriter, r *http.Request) {
}

func GetLogsByContract(w http.ResponseWriter, r *http.Request) {
contractAddress := chi.URLParam(r, "contractAddress")
contractAddress := chi.URLParam(r, "contract")
handleLogsRequest(w, r, contractAddress, "")
}

func GetLogsByContractAndSignature(w http.ResponseWriter, r *http.Request) {
contractAddress := chi.URLParam(r, "contractAddress")
eventSig := chi.URLParam(r, "eventSig")
handleLogsRequest(w, r, contractAddress, eventSig)
contractAddress := chi.URLParam(r, "contract")
eventSignature := chi.URLParam(r, "signature")
handleLogsRequest(w, r, contractAddress, eventSignature)
}

func handleLogsRequest(w http.ResponseWriter, r *http.Request, contractAddress, signature string) {
Expand All @@ -47,6 +48,11 @@ func handleLogsRequest(w http.ResponseWriter, r *http.Request, contractAddress,
return
}

signatureHash := ""
if signature != "" {
signatureHash = crypto.Keccak256Hash([]byte(signature)).Hex()
}

mainStorage, err := getMainStorage()
if err != nil {
log.Error().Err(err).Msg("Error getting main storage")
Expand All @@ -63,7 +69,7 @@ func handleLogsRequest(w http.ResponseWriter, r *http.Request, contractAddress,
Limit: queryParams.Limit,
Aggregates: queryParams.Aggregates,
ContractAddress: contractAddress,
Signature: signature,
Signature: signatureHash,
})
if err != nil {
log.Error().Err(err).Msg("Error querying logs")
Expand All @@ -75,10 +81,10 @@ func handleLogsRequest(w http.ResponseWriter, r *http.Request, contractAddress,
Meta: api.Meta{
ChainIdentifier: chainId,
ContractAddress: contractAddress,
Signature: signature,
Signature: signatureHash,
Page: queryParams.Page,
Limit: queryParams.Limit,
TotalItems: 0, // TODO: Implement total items count
TotalItems: len(logs.Data),
TotalPages: 0, // TODO: Implement total pages count
},
Data: logs.Data,
Expand Down
23 changes: 15 additions & 8 deletions internal/handlers/transactions_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ func GetTransactions(w http.ResponseWriter, r *http.Request) {
}

func GetTransactionsByContract(w http.ResponseWriter, r *http.Request) {
contractAddress := chi.URLParam(r, "contractAddress")
handleTransactionsRequest(w, r, contractAddress, "")
to := chi.URLParam(r, "to")
handleTransactionsRequest(w, r, to, "")
}

func GetTransactionsByContractAndSignature(w http.ResponseWriter, r *http.Request) {
contractAddress := chi.URLParam(r, "contractAddress")
functionSig := chi.URLParam(r, "functionSig")
handleTransactionsRequest(w, r, contractAddress, functionSig)
to := chi.URLParam(r, "to")
// TODO: Implement signature lookup before activating this
// signature := chi.URLParam(r, "signature")
handleTransactionsRequest(w, r, to, "")
}

func handleTransactionsRequest(w http.ResponseWriter, r *http.Request, contractAddress, functionSig string) {
func handleTransactionsRequest(w http.ResponseWriter, r *http.Request, contractAddress, signature string) {
chainId, err := api.GetChainId(r)
if err != nil {
api.BadRequestErrorHandler(w, err)
Expand All @@ -37,6 +38,12 @@ func handleTransactionsRequest(w http.ResponseWriter, r *http.Request, contractA
return
}

signatureHash := ""
// TODO: implement signature lookup
// if signature != "" {
// signatureHash = crypto.Keccak256Hash([]byte(signature)).Hex()
// }

mainStorage, err := getMainStorage()
if err != nil {
log.Error().Err(err).Msg("Error creating storage connector")
Expand All @@ -53,7 +60,7 @@ func handleTransactionsRequest(w http.ResponseWriter, r *http.Request, contractA
Limit: queryParams.Limit,
Aggregates: queryParams.Aggregates,
ContractAddress: contractAddress,
Signature: functionSig,
Signature: signatureHash,
})
if err != nil {
log.Error().Err(err).Msg("Error querying transactions")
Expand All @@ -65,7 +72,7 @@ func handleTransactionsRequest(w http.ResponseWriter, r *http.Request, contractA
Meta: api.Meta{
ChainIdentifier: chainId,
ContractAddress: contractAddress,
Signature: functionSig,
Signature: signature,
Page: queryParams.Page,
Limit: queryParams.Limit,
TotalItems: 0, // TODO: Implement total items count
Expand Down
Loading

0 comments on commit ce8c111

Please sign in to comment.