1- import { ethereum , log } from '@graphprotocol/graph-ts' ;
1+ import { ethereum , log , store } from '@graphprotocol/graph-ts' ;
22import { Block , Block2 } from '../generated/schema' ;
33import { BigInt } from '@graphprotocol/graph-ts' ;
44
@@ -22,4 +22,36 @@ export function handleBlock(block: ethereum.Block): void {
2222 blockEntity3 . number = block . number ;
2323 blockEntity3 . hash = block . hash ;
2424 blockEntity3 . save ( ) ;
25+
26+ if ( block . number . equals ( BigInt . fromI32 ( 1 ) ) ) {
27+ let id = 'TEST' ;
28+ let entity = new Block ( id ) ;
29+ entity . number = block . number ;
30+ entity . hash = block . hash ;
31+ entity . testMessage = 'Created at block 1' ;
32+ log . info ( 'Created entity at block 1' , [ ] ) ;
33+ entity . save ( ) ;
34+ }
35+
36+ if ( block . number . equals ( BigInt . fromI32 ( 2 ) ) ) {
37+ let id = 'TEST' ;
38+ let blockEntity1 = Block . load ( id ) ;
39+ if ( blockEntity1 ) {
40+ // Update the block entity
41+ blockEntity1 . testMessage = 'Updated at block 2' ;
42+ log . info ( 'Updated entity at block 2' , [ ] ) ;
43+ blockEntity1 . save ( ) ;
44+ }
45+ }
46+
47+ if ( block . number . equals ( BigInt . fromI32 ( 3 ) ) ) {
48+ let id = 'TEST' ;
49+ let blockEntity1 = Block . load ( id ) ;
50+ if ( blockEntity1 ) {
51+ blockEntity1 . testMessage = 'Deleted at block 3' ;
52+ log . info ( 'Deleted entity at block 3' , [ ] ) ;
53+ blockEntity1 . save ( ) ;
54+ store . remove ( 'Block' , id ) ;
55+ }
56+ }
2557}
0 commit comments