Get missing fields in transaction data for subgraph event handlers (#102)

* Get missing fields in event transaction

* Cache transaction data for event handlers in subgraph
This commit is contained in:
2021-12-29 13:21:39 +05:30
committed by GitHub
parent 561c2c9066
commit 9b1aa29afd
8 changed files with 128 additions and 35 deletions
+16
View File
@@ -55,3 +55,19 @@ export function decodeHeader (rlp : Uint8Array): any {
export function decodeData (hexLiteral: string): Uint8Array {
return Uint8Array.from(Buffer.from(hexLiteral.slice(2), 'hex'));
}
export function decodeTransaction (rlp : Uint8Array): any {
try {
const data = utils.RLP.decode(rlp);
return {
GasPrice: decodeInteger(data[1], BigInt(0)),
GasLimit: decodeInteger(data[2], BigInt(0)),
Amount: decodeInteger(data[4], BigInt(0)),
Data: data[5]
};
} catch (error: any) {
log(error);
return undefined;
}
}
+4 -4
View File
@@ -225,15 +225,15 @@ export class JobRunner {
blockProgress = await this._indexer.fetchBlockEvents({ cid, blockHash, blockNumber, parentHash, blockTimestamp: timestamp });
}
if (this._indexer.processBlock) {
await this._indexer.processBlock(blockHash, blockNumber);
}
// Check if block has unprocessed events.
if (blockProgress.numProcessedEvents < blockProgress.numEvents) {
await this._jobQueue.pushJob(QUEUE_EVENT_PROCESSING, { kind: JOB_KIND_EVENTS, blockHash: blockProgress.blockHash, publish: true });
}
if (this._indexer.processBlock) {
await this._indexer.processBlock(blockHash, blockNumber);
}
const indexBlockDuration = new Date().getTime() - indexBlockStartTime.getTime();
log(`time:job-runner#_indexBlock: ${indexBlockDuration}ms`);
}
+24
View File
@@ -194,6 +194,7 @@ export const getFullBlock = async (ethClient: EthClient, ethProvider: providers.
const { size } = await provider.send('eth_getBlockByHash', [blockHash, false]);
return {
headerId: fullBlock.id,
cid: fullBlock.cid,
blockNumber: fullBlock.blockNumber,
blockHash: fullBlock.blockHash,
@@ -211,3 +212,26 @@ export const getFullBlock = async (ethClient: EthClient, ethProvider: providers.
size: BigInt(size).toString()
};
};
export const getFullTransaction = async (ethClient: EthClient, headerId: number, txHash: string): Promise<any> => {
const {
ethTransactionCidByHeaderIdAndTxHash: fullTx
} = await ethClient.getFullTransaction({ headerId, txHash });
assert(fullTx.blockByMhKey);
// Decode the transaction data.
const extraData = EthDecoder.decodeTransaction(EthDecoder.decodeData(fullTx.blockByMhKey.data));
assert(extraData);
return {
hash: txHash,
from: fullTx.src,
to: fullTx.dst,
index: fullTx.index,
value: extraData.Amount.toString(),
gasLimit: extraData.GasLimit.toString(),
gasPrice: extraData.GasPrice.toString(),
input: extraData.Data
};
};