mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 16:54:08 +00:00
Get missing block fields (#51)
* Decode header and get missing block fields * Move method to get block data to misc in util * Remove unnecessary encoding of header data
This commit is contained in:
@@ -33,6 +33,10 @@ export interface Block {
|
||||
td: string;
|
||||
txRoot: string;
|
||||
receiptRoot: string;
|
||||
uncleHash: string;
|
||||
difficulty: string;
|
||||
gasLimit: string;
|
||||
gasUsed: string;
|
||||
}
|
||||
|
||||
export interface EventData {
|
||||
@@ -263,9 +267,19 @@ export const createBlock = async (instanceExports: any, blockData: Block): Promi
|
||||
const parentHashByteArray = await ByteArray.fromHexString(parentHashStringPtr);
|
||||
const parentHash = await Bytes.fromByteArray(parentHashByteArray);
|
||||
|
||||
const uncleHashStringPtr = await __newString(blockData.uncleHash);
|
||||
const uncleHashByteArray = await ByteArray.fromHexString(uncleHashStringPtr);
|
||||
const uncleHash = await Bytes.fromByteArray(uncleHashByteArray);
|
||||
|
||||
const blockNumberStringPtr = await __newString(blockData.blockNumber);
|
||||
const blockNumber = await BigInt.fromString(blockNumberStringPtr);
|
||||
|
||||
const gasUsedStringPtr = await __newString(blockData.gasUsed);
|
||||
const gasUsed = await BigInt.fromString(gasUsedStringPtr);
|
||||
|
||||
const gasLimitStringPtr = await __newString(blockData.gasLimit);
|
||||
const gasLimit = await BigInt.fromString(gasLimitStringPtr);
|
||||
|
||||
const timestampStringPtr = await __newString(blockData.timestamp);
|
||||
const blockTimestamp = await BigInt.fromString(timestampStringPtr);
|
||||
|
||||
@@ -281,35 +295,30 @@ export const createBlock = async (instanceExports: any, blockData: Block): Promi
|
||||
const receiptsRootByteArray = await ByteArray.fromHexString(receiptRootStringPtr);
|
||||
const receiptsRoot = await Bytes.fromByteArray(receiptsRootByteArray);
|
||||
|
||||
const difficultyStringPtr = await __newString(blockData.difficulty);
|
||||
const difficulty = await BigInt.fromString(difficultyStringPtr);
|
||||
|
||||
const tdStringPtr = await __newString(blockData.td);
|
||||
const totalDifficulty = await BigInt.fromString(tdStringPtr);
|
||||
|
||||
const unclesHashPtr = await Bytes.empty();
|
||||
const authorPtr = await Address.zero();
|
||||
const gasUsedPtr = await BigInt.fromI32(0);
|
||||
const gasLimitPtr = await BigInt.fromI32(0);
|
||||
const difficultyPtr = await BigInt.fromI32(0);
|
||||
|
||||
// Missing fields from watcher in block data:
|
||||
// unclesHash
|
||||
// author
|
||||
// gasUsed
|
||||
// gasLimit
|
||||
// difficulty
|
||||
// size
|
||||
return await ethereum.Block.__new(
|
||||
blockHash,
|
||||
parentHash,
|
||||
unclesHashPtr,
|
||||
uncleHash,
|
||||
authorPtr,
|
||||
stateRoot,
|
||||
transactionsRoot,
|
||||
receiptsRoot,
|
||||
blockNumber,
|
||||
gasUsedPtr,
|
||||
gasLimitPtr,
|
||||
gasUsed,
|
||||
gasLimit,
|
||||
blockTimestamp,
|
||||
difficultyPtr,
|
||||
difficulty,
|
||||
totalDifficulty,
|
||||
null
|
||||
);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ContractInterface, utils } from 'ethers';
|
||||
|
||||
import { ResultObject } from '@vulcanize/assemblyscript/lib/loader';
|
||||
import { EthClient } from '@vulcanize/ipld-eth-client';
|
||||
import { IndexerInterface } from '@vulcanize/util';
|
||||
import { IndexerInterface, getFullBlock } from '@vulcanize/util';
|
||||
|
||||
import { createBlock, createEvent, getSubgraphConfig, resolveEntityFieldConflicts } from './utils';
|
||||
import { Context, instantiate } from './loader';
|
||||
@@ -98,13 +98,8 @@ export class GraphWatcher {
|
||||
async handleEvent (eventData: any) {
|
||||
const { contract, event, eventSignature, block, tx, eventIndex } = eventData;
|
||||
|
||||
const {
|
||||
allEthHeaderCids: {
|
||||
nodes: [
|
||||
blockData
|
||||
]
|
||||
}
|
||||
} = await this._postgraphileClient.getBlocks({ blockHash: block.hash });
|
||||
// TODO: Use blockData fetched in handleBlock.
|
||||
const blockData = await getFullBlock(this._postgraphileClient, block.hash);
|
||||
|
||||
this._context.event.block = blockData;
|
||||
|
||||
@@ -150,13 +145,7 @@ export class GraphWatcher {
|
||||
}
|
||||
|
||||
async handleBlock (blockHash: string) {
|
||||
const {
|
||||
allEthHeaderCids: {
|
||||
nodes: [
|
||||
blockData
|
||||
]
|
||||
}
|
||||
} = await this._postgraphileClient.getBlocks({ blockHash });
|
||||
const blockData = await getFullBlock(this._postgraphileClient, blockHash);
|
||||
|
||||
// Call block handler(s) for each contract.
|
||||
for (const dataSource of this._dataSources) {
|
||||
|
||||
Reference in New Issue
Block a user