-
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: fetch events by src addresses #44
Conversation
async fetchEventsBySrcAddress(params: { | ||
chainId: ChainId; | ||
srcAddresses: Address[]; | ||
from?: { | ||
blockNumber?: number; | ||
logIndex?: number; | ||
}; | ||
to: { | ||
blockNumber: number; | ||
logIndex: number; | ||
}; | ||
limit?: number; | ||
}): Promise<AnyIndexerFetchedEvent[]> { |
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 a sidenote, you got the fetchEventsByBlockNumberAndLogIndex
method that receives multiple parameters and you got this method that receives a params
object.
Is there any particular reason for that?
And another question 👉 have you ever considered leveraging some kind of query builder pattern for the event fetcher? You could end up with a cool class:
const query = EventsFetcher.buildQuery()
.withChainId(chainId)
.withSrcAddressess(addresses)
.withBlockNumber(blockNumber)
...
If you envision having more fetchEventsBy...
methods, I'd consider this hehe
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.
regarding first, now that you mention that you're right, originally i wrote the method only with to
param but when adding the from
actually both methods can be combined into one
regarding second, i like query builders 😄 but i don't think we will benefit too much for now
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 keep the old method until i integrate it with the rest of the code cuz if not i'll break everything
try { | ||
const { chainId, srcAddresses, from, to, limit = 100 } = params; | ||
const { blockNumber: toBlock, logIndex: toLogIndex } = to; | ||
const { blockNumber: fromBlock, logIndex: fromLogIndex } = from ?? { |
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.
What if from
is {}
?
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.
good catch
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.
just smoll comments in docs and method signature
from?: { | ||
blockNumber?: number; | ||
logIndex?: number; | ||
}; | ||
to: { | ||
blockNumber: number; | ||
logIndex: 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 it be like this ?
from?: { | |
blockNumber?: number; | |
logIndex?: number; | |
}; | |
to: { | |
blockNumber: number; | |
logIndex: number; | |
from: { | |
blockNumber: number; | |
logIndex: number; | |
}; | |
to?: { | |
blockNumber: number; | |
logIndex: number; |
/** | ||
* Fetch the events by src address, block number and log index for a chain | ||
* @param chainId id of the chain | ||
* @param srcAddresses src addresses to fetch events from | ||
* @param toBlock block number to fetch events from | ||
* @param logIndex log index in the block to fetch events from | ||
* @param limit limit of events to fetch | ||
*/ |
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.
is this ok ?
{ block_number: { _gt: $fromBlock } }, | ||
{ | ||
_and: [ | ||
{ block_number: { _eq: $fromBlock } }, | ||
{ log_index: { _gt: $fromLogIndex } } | ||
] | ||
} | ||
] |
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.
This might not be relevant as you might be using this provider in a super specific way but how would you get all events from a single block?
I can only think of something like this:
from: { blockNumber: x, logIndex: 0 }
to: { blockNumber: x + 1, logIndex: 0 }
But it misses the log 0 from block x and includes log 0 from block x + 1.
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.
didn't think of this case since we fetch events individually (blockNumber and logIndex), not by blocks but i get your point. i will add it to tech debt
🤖 Linear
Closes GIT-205
Description
We want to be able to fetch all events for a now-handleable strategy, so we add a method to fetch all events between Genesis and
lastProcessedEvent
for a group ofsrc addresses
(all that corresponds to astrategyId
)Checklist before requesting a review