1- import { Entity , log , store } from '@graphprotocol/graph-ts' ;
1+ import { Entity , log , store , BigInt , EntityTrigger , EntityOp } from '@graphprotocol/graph-ts' ;
2+ import { Block } from '../generated/subgraph-Qmaqf8cRxfxbduZppSHKG9DMuX5JZPMoGuwGb2DQuo48sq' ;
23import { MirrorBlock } from '../generated/schema' ;
34
4- export class EntityTrigger {
5- constructor (
6- public entityOp : u32 ,
7- public entityType : string ,
8- public entity : Entity ,
9- public vid : i64 ,
10- ) { }
11- }
12-
13- export function handleEntity ( trigger : EntityTrigger ) : void {
14- let blockEntity = trigger . entity ;
15- let blockNumber = blockEntity . getBigInt ( 'number' ) ;
16- let blockHash = blockEntity . getBytes ( 'hash' ) ;
17- let testMessage = blockEntity . get ( 'testMessage' ) ;
18- let id = blockEntity . getString ( 'id' ) ;
5+ export function handleEntity ( trigger : EntityTrigger < Block > ) : void {
6+ let blockEntity = trigger . data ;
7+ let id = blockEntity . id ;
198
20- log . info ( 'Block number: {}' , [ blockNumber . toString ( ) ] ) ;
21-
22- if ( trigger . entityOp == 2 ) {
9+ if ( trigger . operation === EntityOp . Remove ) {
2310 log . info ( 'Removing block entity with id: {}' , [ id ] ) ;
2411 store . remove ( 'MirrorBlock' , id ) ;
2512 return ;
2613 }
2714
2815 let block = loadOrCreateMirrorBlock ( id ) ;
29- block . number = blockNumber ;
30- block . hash = blockHash ;
31- if ( testMessage ) {
32- block . testMessage = testMessage . toString ( ) ;
16+ block . number = blockEntity . number ;
17+ block . hash = blockEntity . hash ;
18+
19+ if ( blockEntity . testMessage ) {
20+ block . testMessage = blockEntity . testMessage ;
3321 }
3422
3523 block . save ( ) ;
@@ -41,6 +29,5 @@ export function loadOrCreateMirrorBlock(id: string): MirrorBlock {
4129 log . info ( 'Creating new block entity with id: {}' , [ id ] ) ;
4230 block = new MirrorBlock ( id ) ;
4331 }
44-
4532 return block ;
4633}
0 commit comments