Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v2/contracts/{chainId} API endpoint #1857

Merged
merged 9 commits into from
Jan 20, 2025
Merged

Conversation

manuelwedler
Copy link
Contributor

@manuelwedler manuelwedler commented Jan 16, 2025

See #1827

Adds the v2/contracts/{chainId} endpoint as described in https://sourcify.stoplight.io/docs/sourcify-apiv2/kqms8dret0zja-list-of-verified-contracts-per-chain

Includes the initial setup of routes and types needed for API v2, as it's the first endpoint. Also refactors some API v1 code to the apiv1 folder.

Pagination issue

I discovered an issue about the pagination design of the API. The issue is that we include the totalResults in the response. To gather this information, we run a very long db query for counting the matches. It took 60-90 seconds in my trials on production. This issue is already present in API v1.

I think we can still review this PR, and resolve this issue in another when we decided how to go about it.

Includes the initial setup of routes and types needed for API v2, as it's the first endpoint
Some shells require mocha's `recursive` option to go through all subdirectories
@manuelwedler manuelwedler changed the title Apiv2 list endpoint Add v2/contracts/{chainId} API endpoint Jan 16, 2025
@manuelwedler
Copy link
Contributor Author

We decided to implement id based pagination to circumvent the above issue.

We need to add the id from sourcify_matches to our VerifiedContractMinimal object from the API design.

The API query should look like this then: /v2/contracts/{chainId}?limit=20&afterId=5500608&sort=desc

@marcocastignoli you can wait with reviewing until I implemented this.

@kuzdogan
Copy link
Member

Just to make sure, should it be from sourcify_matches or verified_contracts?

@manuelwedler
Copy link
Contributor Author

It should be sourcify_matches.id. verified_contracts.id wouldn't be unique to the chainId and address, right?

Copy link
Member

@marcocastignoli marcocastignoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll review again after you implement the new pagination. Great job! 👍

services/server/.mocharc.json Show resolved Hide resolved
services/server/package.json Show resolved Hide resolved
services/server/src/server/apiv2/errors.ts Show resolved Hide resolved
services/server/src/server/types.ts Outdated Show resolved Hide resolved
services/server/src/server/apiv2/errors.ts Show resolved Hide resolved
services/server/src/server/apiv2/errors.ts Show resolved Hide resolved
Copy link
Member

@marcocastignoli marcocastignoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@manuelwedler manuelwedler merged commit e67fa44 into apiv2 Jan 20, 2025
6 checks passed
manuelwedler added a commit that referenced this pull request Jan 30, 2025
* Move `safeHandler` to common.ts

* Update API v2 spec

* Add `v2/contracts/{chainId}` API endpoint

Includes the initial setup of routes and types needed for API v2, as it's the first endpoint

* Fix server test commands

Some shells require mocha's `recursive` option to go through all subdirectories

* Move API v1 routes to apiv1 folder

* Update API v2 spec

* Change pagination to be id based

* Add `getTotalMatchLevel` util function

* Rename MatchLevel types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: COMPLETED
Development

Successfully merging this pull request may close these issues.

3 participants