File tree Expand file tree Collapse file tree 5 files changed +101
-0
lines changed
tests/integration-tests/multiple-subgraph-data-sources Expand file tree Collapse file tree 5 files changed +101
-0
lines changed Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "anonymous": false,
4
+ "inputs": [
5
+ {
6
+ "indexed": false,
7
+ "internalType": "string",
8
+ "name": "testCommand",
9
+ "type": "string"
10
+ }
11
+ ],
12
+ "name": "TestEvent",
13
+ "type": "event"
14
+ }
15
+ ]
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " subgraph-data-sources" ,
3
+ "version" : " 0.1.0" ,
4
+ "scripts" : {
5
+ "codegen" : " graph codegen --skip-migrations" ,
6
+ "create:test" : " graph create test/subgraph-data-sources --node $GRAPH_NODE_ADMIN_URI" ,
7
+ "deploy:test" : " graph deploy test/subgraph-data-sources --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
8
+ },
9
+ "devDependencies" : {
10
+ "@graphprotocol/graph-cli" : " 0.79.0-alpha-20240711124603-49edf22" ,
11
+ "@graphprotocol/graph-ts" : " 0.31.0"
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ type MirrorBlock @entity {
2
+ id : String !
3
+ number : BigInt !
4
+ hash : Bytes !
5
+ testMessage : String
6
+ }
Original file line number Diff line number Diff line change
1
+ import { Entity , log , store } from '@graphprotocol/graph-ts' ;
2
+ import { MirrorBlock } from '../generated/schema' ;
3
+
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' ) ;
19
+
20
+ log . info ( 'Block number: {}' , [ blockNumber . toString ( ) ] ) ;
21
+
22
+ if ( trigger . entityOp == 2 ) {
23
+ log . info ( 'Removing block entity with id: {}' , [ id ] ) ;
24
+ store . remove ( 'MirrorBlock' , id ) ;
25
+ return ;
26
+ }
27
+
28
+ let block = loadOrCreateMirrorBlock ( id ) ;
29
+ block . number = blockNumber ;
30
+ block . hash = blockHash ;
31
+ if ( testMessage ) {
32
+ block . testMessage = testMessage . toString ( ) ;
33
+ }
34
+
35
+ block . save ( ) ;
36
+ }
37
+
38
+ export function loadOrCreateMirrorBlock ( id : string ) : MirrorBlock {
39
+ let block = MirrorBlock . load ( id ) ;
40
+ if ( ! block ) {
41
+ log . info ( 'Creating new block entity with id: {}' , [ id ] ) ;
42
+ block = new MirrorBlock ( id ) ;
43
+ }
44
+
45
+ return block ;
46
+ }
Original file line number Diff line number Diff line change
1
+ specVersion : 1.3.0
2
+ schema :
3
+ file : ./schema.graphql
4
+ dataSources :
5
+ - kind : subgraph
6
+ name : Contract
7
+ network : test
8
+ source :
9
+ address : ' Qmaqf8cRxfxbduZppSHKG9DMuX5JZPMoGuwGb2DQuo48sq'
10
+ startBlock : 0
11
+ mapping :
12
+ apiVersion : 0.0.7
13
+ language : wasm/assemblyscript
14
+ entities :
15
+ - Gravatar
16
+ handlers :
17
+ - handler : handleEntity
18
+ entity : Block
19
+ - handler : handleEntity
20
+ entity : Block2
21
+ file : ./src/mapping.ts
You can’t perform that action at this time.
0 commit comments