-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add gas used and transactions fee #1
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
Open
alexandre-abrioux
wants to merge
14
commits into
cartesi:main
Choose a base branch
from
alexandre-abrioux:gas-used
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
997697e
feat: add gas used and transactions fee
alexandre-abrioux 8bc0fe7
upgrade thegraph dependencies
alexandre-abrioux 8c3b943
add receipts
alexandre-abrioux b672303
add test
alexandre-abrioux 066b327
fix tests
alexandre-abrioux 8cb0458
udpate thegraph dependencies
alexandre-abrioux 82d2ce9
update version
alexandre-abrioux 9413931
fix missing summary.totalTransactionFee
alexandre-abrioux 600a8b6
yaml receipt true
alexandre-abrioux 77acc2e
remove export
alexandre-abrioux d21bfd7
update er schema
alexandre-abrioux 42bf0df
fix tests
alexandre-abrioux 9fa1230
push dockerignore
alexandre-abrioux 96b2c42
remove useless receipts
alexandre-abrioux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| # .dockerignore is a symbolic link to .gitignore | ||
| .bin | ||
| .vscode | ||
| build | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| version: '3.4' | ||
| services: | ||
| matchstick: | ||
| image: cartesi/subgraph-matchstick:dev | ||
| build: | ||
| dockerfile: tests/.docker | ||
| target: base | ||
| container_name: cartesi-subgraph-matchstick | ||
| volumes: | ||
| - .:/matchstick |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { Address, BigInt, ethereum, log } from "@graphprotocol/graph-ts" | ||
| import { Block } from "../generated/schema" | ||
| import * as nodes from "./node" | ||
| import * as chains from "./chain" | ||
| import * as users from "./user" | ||
| import * as summary from "./summary" | ||
| import { BlockProduced } from "../generated/BlockSelector/BlockSelector" | ||
|
|
||
| function createBlock(event: ethereum.Event): Block { | ||
| const block = new Block(event.transaction.hash.toHex()) | ||
| block.timestamp = event.block.timestamp | ||
| block.gasPrice = event.transaction.gasPrice | ||
| block.gasLimit = event.transaction.gasLimit | ||
| block.gasUsed = (event.receipt as ethereum.TransactionReceipt).gasUsed | ||
| block.transactionFee = block.gasUsed.times(block.gasPrice) | ||
| return block | ||
| } | ||
|
|
||
| abstract class RewardedCommonParams { | ||
| abstract get index(): BigInt | ||
| abstract get worker(): Address | ||
| abstract get user(): Address | ||
| } | ||
|
|
||
| abstract class RewardedCommon extends ethereum.Event { | ||
| abstract get params(): RewardedCommonParams | ||
| } | ||
|
|
||
| export function handleRewardedInner<T extends RewardedCommon>( | ||
| event: T, | ||
| reward: BigInt | ||
| ): void { | ||
| // handle node | ||
| let node = nodes.loadOrCreate( | ||
| event.params.user, | ||
| event.params.worker, | ||
| event.block.timestamp | ||
| ) | ||
| node.totalBlocks++ | ||
| node.status = "Authorized" | ||
| node.totalReward = node.totalReward.plus(reward) | ||
| node.save() | ||
|
|
||
| // handle chain | ||
| let posAddress = event.address.toHex() | ||
| let chain = chains.loadOrCreate( | ||
| posAddress, | ||
| event.params.index.toI32(), | ||
| event.block.timestamp | ||
| ) | ||
| chain.totalBlocks++ | ||
| chain.totalReward = chain.totalReward.plus(reward) | ||
| chain.save() | ||
|
|
||
| // Rewarded is always called before BlockProduced, so create Block here | ||
| let block = Block.load(event.transaction.hash.toHex()) | ||
| if (block == null) { | ||
| block = createBlock(event) | ||
| } | ||
| block.chain = chain.id | ||
| block.reward = reward | ||
| block.producer = event.params.user.toHex() | ||
| block.node = event.params.worker.toHex() | ||
| block.save() | ||
|
|
||
| // handle user | ||
| let user = users.loadOrCreate(event.params.user) | ||
| user.totalBlocks++ | ||
| user.totalReward = user.totalReward.plus(reward) | ||
| user.totalTransactionFee = user.totalTransactionFee.plus( | ||
| block.transactionFee | ||
| ) | ||
|
Comment on lines
+70
to
+72
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| user.save() | ||
|
|
||
| // handle global summary | ||
| let s = summary.loadOrCreate() | ||
| s.totalBlocks++ | ||
| s.totalReward = s.totalReward.plus(reward) | ||
| s.totalTransactionFee = s.totalTransactionFee.plus(block.transactionFee) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| s.save() | ||
| } | ||
|
|
||
| export function handleBlockProduced(event: BlockProduced): void { | ||
| // load Block and fill other properties | ||
| let block = Block.load(event.transaction.hash.toHex()) | ||
| if (block == null) { | ||
| block = createBlock(event) | ||
| } | ||
| block.number = event.params.blockNumber.toI32() | ||
| block.difficulty = event.params.difficulty | ||
| block.save() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Refacto: similar code from
block.tsandblock-1.0.tshave been moved toblock-common.ts