-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: events fetcher & indexer client #4
Conversation
@@ -0,0 +1,10 @@ | |||
import { AnyProtocolEvent } from "@grants-stack-indexer/shared"; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add natspec
limit: number = 100, | ||
): Promise<AnyProtocolEvent[]> { | ||
try { | ||
const response = (await this.client.rawRequest(gql` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this library provide a way to type the response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will investigate about that , maybe we can use some generics :)
query getEventsByChainIdBlockNumberAndLogIndex { | ||
raw_events( | ||
where: { | ||
chain_id: { _eq: ${chainId} } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ok for now but rather than using string interpolation we can use variables which also prevent injection issues
see variables:
https://graphql.org/learn/queries/
in this case I think you could do this
const query = gql`
query getEventsByChainIdBlockNumberAndLogIndex($chainId: Int!, $blockNumber: Int!, $logIndex: Int!, $limit: Int!) {
raw_events(
where: {
chain_id: { _eq: $chainId }
block_number: { _gte: $blockNumber }
log_index: { _gt: $logIndex }
}
limit: $limit
) {
block_number
block_timestamp
chain_id
contract_name
event_name
log_index
params
src_address
}
}
`;
const response = await this.client.request(query, {
chainId, blockNumber, logIndex, limit,
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this recommendation, this makes lot more sense :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting to get deep into the core of the project 🫡
export interface IEventsFetcher { | ||
fetcEventsByBlockNumberAndLogIndex( | ||
chainId: number, | ||
blockNumber: number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should blockNumber
be a BigInt
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm thinking if ProtocolEvent["block_number"]
should also be bigint
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need it actually. Number.MAX_SAFE_INTEGER = 9007199254740991
:rofl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Viem treats it like bigint
, we will have an inconsistency here. We need to define a common type at least to the internal limits of our backend, and only convert to number or bigint when interfacing with external (IndexerClient, Viem lib, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along the lines of Nigiri's comment, it's more of a semantic type thingy.
Whenever you get a block number out of viem
or any other client, you as a dev will need to know (and be extremely sure) that you are working with a particular set of block numbers that can be safely casted from bigint
to number
. By using a bigint
, you just forget about that problem in the future. You move from a "it will probably work" scenario to a "it works" scenario.
this.client.setHeader("x-hasura-admin-secret", secret); | ||
} | ||
|
||
public async getEventsByBlockNumberAndLogIndex( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super small detail but feels like it could be more descriptive to name this method as
public async getEventsByBlockNumberAndLogIndex( | |
public async getEventsAfterBlockNumberAndLogIndex( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interested in seeing if it's possible to type gql requests, would be awesome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as Yaco said, would be great to type the GraphQL queries (maybe defining the queries in a separate .gql file or the schemas)
🤖 Linear
Closes GIT-53 GIT-84 GIT-85
Description
Implementation of
data-flow
=>EventsFetcher
indexer-client
=>EnvioIndexerClient
Checklist before requesting a review