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

feat: add getNumberOfInputsBeforeCurrentBlock #339

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

guidanoli
Copy link
Collaborator

No description provided.

return snapshot.numberOfInputsBeforeBlock;
} else {
// snapshot.blockNumber < block.number
return getNumberOfInputs(appContract);
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the reason for using getNumberOfInputs rather than snapshots here :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because _snapshots only holds the index of the first input of the block.
If we are not in the same block in which the last snapshot was taken, then we have to return the total number of inputs up until now.
Let me illustrate:

at first, snapshot = (block=0, #inputs=0)
then an input is added on block 7, snapshot = (block=7, #inputs=1)
another input is added on block 7, snapshot = (block=7, #inputs=1) [the same]
then an input is added on block 8, snapshot = (block=8, #inputs=3)
another input is added on block 8, snapshot = (block=8, #inputs=3) [the same]
now, we're on block 42
if we used the snapshot, it would return 3,
but before the current block (42), there are 4 inputs already
so we need to use the current number of inputs

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Yeah it's clear. Thanks for the illustration!!

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