Invoke subgraph block handlers (#43)

* Add a test case to eden test to call the block handler

* Add a block handler in example subgraph and call it in a watcher

* Use an array map to call all the block handlers for a contract

* Await on all the promises returned by block handlers map
This commit is contained in:
prathamesh0
2021-12-28 16:08:05 +05:30
committed by nabarun
parent 06ba24e38f
commit 16bb955213
8 changed files with 204 additions and 96 deletions
@@ -1,4 +1,4 @@
import { Address, log, BigInt, BigDecimal, ByteArray, dataSource } from '@graphprotocol/graph-ts';
import { Address, log, BigInt, BigDecimal, ByteArray, dataSource, ethereum } from '@graphprotocol/graph-ts';
import {
Example1,
@@ -54,6 +54,30 @@ export function handleTest (event: Test): void {
// - contract.getMethod(...)
}
export function handleBlock (block: ethereum.Block): void {
log.debug('block.hash: {}', [block.hash.toHexString()]);
log.debug('block.parentHash: {}', [block.parentHash.toHexString()]);
log.debug('block.unclesHash: {}', [block.unclesHash.toHexString()]);
log.debug('block.author: {}', [block.author.toHexString()]);
log.debug('block.stateRoot: {}', [block.stateRoot.toHexString()]);
log.debug('block.transactionsRoot: {}', [block.transactionsRoot.toHexString()]);
log.debug('block.receiptsRoot: {}', [block.receiptsRoot.toHexString()]);
log.debug('block.number: {}', [block.number.toString()]);
log.debug('block.gasUsed: {}', [block.gasUsed.toString()]);
log.debug('block.gasLimit: {}', [block.gasLimit.toString()]);
log.debug('block.timestamp: {}', [block.timestamp.toString()]);
log.debug('block.difficulty: {}', [block.difficulty.toString()]);
log.debug('block.totalDifficulty: {}', [block.totalDifficulty.toString()]);
const blockSize = block.size;
if (blockSize) {
log.debug('block.size: {}', [blockSize.toString()]);
} else {
log.debug('block.size: {}', ['null']);
}
}
export function testEthCall (): void {
log.debug('In test eth call', []);