Skip to content

[SUBGRAPH] Add gasUsed property to all events #1199

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

Merged
merged 6 commits into from
Dec 6, 2022
Merged

Conversation

0xdavinchee
Copy link
Contributor

  • bump subgraph package versions
  • add gasUsed property to all event entities
  • add tests for gasUsed property

* bump subgraph package versions
* add `gasUsed` property to all event entities
* add tests for `gasUsed` property
@0xdavinchee 0xdavinchee requested review from kasparkallas, hellwolf and a team as code owners December 5, 2022 14:31
@0xdavinchee 0xdavinchee linked an issue Dec 5, 2022 that may be closed by this pull request
if (event.receipt) {
// @note if we don't cast event.receipt as ethereum.TransactionReceipt,
// we get a compile error because it thinks event.receipt is:
// ethereum.TransactionReceipt | null
Copy link
Contributor

@kasparkallas kasparkallas Dec 6, 2022

Choose a reason for hiding this comment

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

Normally TS should be able to infer the correct type with this logic:

    const receipt = event.receipt;
    if (receipt) {
        entity.set("gasUsed", Value.fromBigInt(receipt.gasUsed));
    } else {
        entity.set("gasUsed", Value.fromBigInt(BIG_INT_ZERO));
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I think someone from their side suggested this too, will make this change 👍🏼

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the comment too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

const receipt = event.receipt as ethereum.TransactionReceipt;
entity.set("gasUsed", Value.fromBigInt(receipt.gasUsed));
} else {
entity.set("gasUsed", Value.fromBigInt(BIG_INT_ZERO));
Copy link
Contributor

Choose a reason for hiding this comment

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

If the receipt should always be present (i.e. specified in the .yaml) then I'd prefer throwing in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true

Copy link
Contributor

@kasparkallas kasparkallas Dec 6, 2022

Choose a reason for hiding this comment

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

It's not going to throw ATM as the else-block is just removed? 😛

Copy link
Contributor Author

@0xdavinchee 0xdavinchee Dec 6, 2022

Choose a reason for hiding this comment

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

it will throw because when we go and try to save the entity, this field is non-nullable

* remove casting
* let it break if unable to get receipt
@0xdavinchee 0xdavinchee merged commit 1f84a8f into dev Dec 6, 2022
@0xdavinchee 0xdavinchee deleted the subgraph-gas-used branch December 6, 2022 12:31
@github-actions
Copy link

github-actions bot commented Dec 6, 2022

XKCD Comic Relif

Link: https://xkcd.com/1199
https://xkcd.com/1199

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.

[SUBGRAPH] add gasUsed property
3 participants