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

Rationalize search API HTTP error codes and add hosts and v2 contracts to search #161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chris124567
Copy link
Member

@chris124567 chris124567 commented Jan 17, 2025

Allow the search endpoint to see if a v2 contract with the specified ID or a host with the specified pubkey exists. Ed25519 pubkeys and Hash256 values are both 32 bytes and we already strip prefixes on /search/:id so this works out.

Also, we now use errors that make more sense on the search endpoint. Previously we would just 500 on all errors. Now:

  • If we get a malformed ID, return 400
  • If we get an ID that we cannot find in the DB, return 404
  • If we get an error in searching the DB, return 500
  • Else return 200 and the search result

@chris124567 chris124567 marked this pull request as draft January 17, 2025 18:15
@chris124567 chris124567 changed the title Add hosts and v2 contracts to search Rationalize search API HTTP error codes and add hosts and v2 contracts to search Jan 17, 2025
@chris124567 chris124567 marked this pull request as ready for review January 17, 2025 22:09
@@ -445,5 +449,19 @@ func (e *Explorer) Search(id types.Hash256) (SearchType, error) {
return SearchTypeContract, nil
}

return SearchTypeInvalid, errors.New("no such element")
v2Contracts, err := e.V2Contracts([]types.FileContractID{types.FileContractID(id)})
Copy link
Member

Choose a reason for hiding this comment

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

Good opportunity to clean this up by implementing it directly in the database. Will reduce IO since you're not loading data you're going to throw away and probably improve performance.

return
}

trunc := id[:maxLen]
trunc := id[:idLen]
result, err := s.e.Search(types.Hash256(trunc))
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably make the search term a string instead since you have to support prefixed keys too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants