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

Refactor events and DB #7

Merged
merged 4 commits into from
Jan 10, 2024

Conversation

avichalp
Copy link
Collaborator

@avichalp avichalp commented Jan 6, 2024

This PR achieves the following:

  • Moves the SQL queries from code into separate .sql files and use prepared queries.
  • Moves config such as contract addresses and db path into a separate config.toml
  • Adds a subscribe method that runs in a loop in the background to poll on the getLogs endpoint to fetch new events (todo: move to websocket connection in future).
  • Refactor some exiting Indexing code.
  • Adds a unit test for parsing Register events (todo: needs to add more tests later)

Signed-off-by: avichalp <hi@avichalp.me>
Signed-off-by: avichalp <hi@avichalp.me>
Signed-off-by: avichalp <hi@avichalp.me>
Signed-off-by: avichalp <hi@avichalp.me>
@@ -0,0 +1,26 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry i'm not familiar with sqlx, but what are these json files and are they ok to be committed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sqlx uses these JSON files for compile time SQL checks without needing an active database connection. For instance, if you change a SQL query that is being used, but your new query has a wrong column name it will be caught at the compile time.

To include a new .sqlx file for a new query, you would run sqlx prepare (I have included a command in Makefile for this.)

I think it would be helpful if we commit these files. Otherwise, if you want this kind of check at dev time, you must generate these files every time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

here is a nice explanation of what this is doing from the readme

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome, ty!

@@ -0,0 +1,9 @@
db_path = "sqlite:./farcaster.db"
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥 - thank you for setting this up

Copy link
Contributor

Choose a reason for hiding this comment

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

(i meant the config file)

}

impl IdRegistry {
impl<T: JsonRpcClient + Clone> Contract<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

ah, we're getting there 😆

@haardikk21 haardikk21 merged commit 9045a67 into OpenFarcaster:main Jan 10, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants