Skip to content

Conversation

@alexandre-abrioux
Copy link

@alexandre-abrioux alexandre-abrioux commented Mar 2, 2022

This PR adds new properties to the following entities:

  • gasUsed and transactionFee to Block, with transactionFee = gasUsed x gasPrice
  • totalTransactionFee to User
  • totalTransactionFee to Summary

This change was made possible thanks to graphprotocol/graph-node#3218 and the new TransactionReceipt that is now available in the AssemblyScript API version 0.0.7: https://thegraph.com/docs/en/developer/assemblyscript-api/#versions

Mics

A Dockerfile was added for convenience to test the subgraph without the need to download matchstick binary. It is based on the one found in the documentation.


// create a user with 500 maturing
let user = new User(address)
let user = loadOrCreate(Address.fromString(address))
Copy link
Author

Choose a reason for hiding this comment

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

Since graphprotocol/graph-tooling@629176c the code generation of graph-cli does not assign default values for entities, so we need to initialize ourselves all properties.

@alexandre-abrioux alexandre-abrioux marked this pull request as ready for review May 31, 2022 01:29
@alexandre-abrioux alexandre-abrioux changed the title (WIP) feat: add gas used and transactions fee feat: add gas used and transactions fee May 31, 2022
@@ -0,0 +1 @@
.gitignore No newline at end of file
Copy link
Author

Choose a reason for hiding this comment

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

This is a symlink to .gitignore


export function handleRewarded(event: Rewarded): void {
let reward = event.params.userReward.plus(event.params.beneficiaryReward)

Copy link
Author

@alexandre-abrioux alexandre-abrioux May 31, 2022

Choose a reason for hiding this comment

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

Refacto: similar code from block.ts and block-1.0.ts have been moved to block-common.ts

Comment on lines +70 to +72
user.totalTransactionFee = user.totalTransactionFee.plus(
block.transactionFee
)
Copy link
Author

Choose a reason for hiding this comment

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

In this big code block that was moved, those 3 lines were added

let s = summary.loadOrCreate()
s.totalBlocks++
s.totalReward = s.totalReward.plus(reward)
s.totalTransactionFee = s.totalTransactionFee.plus(block.transactionFee)
Copy link
Author

Choose a reason for hiding this comment

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

In this big code block that was moved, this line was also added

handler: handleNewChain
- event: "Rewarded(indexed uint256,indexed address,indexed address,uint256)"
handler: handleRewarded
receipt: true
Copy link
Author

Choose a reason for hiding this comment

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

This is how we ask the Graph Node to fetch the receipt and pass it down to the Subgraph event

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.

1 participant