@@ -21,6 +21,7 @@ dataSources:
21
21
entities:
22
22
- ExampleEvent
23
23
- ExampleEvent1
24
+ - TupleArrayEvent
24
25
abis:
25
26
- name: Contract
26
27
file: ./abis/Contract.json
@@ -29,6 +30,8 @@ dataSources:
29
30
handler: handleExampleEvent
30
31
- event: ExampleEvent(bytes32)
31
32
handler: handleExampleEvent1
33
+ - event: TupleArrayEvent((uint256,address)[],address[])
34
+ handler: handleTupleArrayEvent
32
35
file: ./src/contract.ts
33
36
"
34
37
` ;
@@ -38,7 +41,8 @@ exports[`Ethereum subgraph scaffolding > Mapping (default) 1`] = `
38
41
import {
39
42
Contract ,
40
43
ExampleEvent ,
41
- ExampleEvent1
44
+ ExampleEvent1 ,
45
+ TupleArrayEvent
42
46
} from "../generated/Contract/Contract"
43
47
import { ExampleEntity } from "../generated/schema"
44
48
@@ -89,15 +93,23 @@ export function handleExampleEvent(event: ExampleEvent): void {
89
93
}
90
94
91
95
export function handleExampleEvent1(event: ExampleEvent1): void { }
96
+
97
+ export function handleTupleArrayEvent(event: TupleArrayEvent): void { }
92
98
"
93
99
` ;
94
100
95
101
exports [` Ethereum subgraph scaffolding > Mapping (for indexing events) 1` ] = `
96
102
"import {
97
103
ExampleEvent as ExampleEventEvent ,
98
- ExampleEvent1 as ExampleEvent1Event
104
+ ExampleEvent1 as ExampleEvent1Event ,
105
+ TupleArrayEvent as TupleArrayEventEvent
99
106
} from "../generated/Contract/Contract"
100
- import { ExampleEvent , ExampleEvent1 } from "../generated/schema"
107
+ import {
108
+ ExampleEvent ,
109
+ ExampleEvent1 ,
110
+ TupleArrayEvent
111
+ } from "../generated/schema"
112
+ import { Bytes } from "@graphprotocol/graph-ts"
101
113
102
114
export function handleExampleEvent(event: ExampleEventEvent): void {
103
115
let entity = new ExampleEvent (
@@ -134,6 +146,82 @@ export function handleExampleEvent1(event: ExampleEvent1Event): void {
134
146
135
147
entity .save ()
136
148
}
149
+
150
+ export function handleTupleArrayEvent(event: TupleArrayEventEvent): void {
151
+ let entity = new TupleArrayEvent (
152
+ event .transaction .hash .concatI32 (event .logIndex .toI32 ())
153
+ )
154
+ entity .tupleArray = changetype <Bytes []>(event .params .tupleArray )
155
+ entity .addressArray = changetype <Bytes []>(event .params .addressArray )
156
+
157
+ entity .blockNumber = event .block .number
158
+ entity .blockTimestamp = event .block .timestamp
159
+ entity .transactionHash = event .transaction .hash
160
+
161
+ entity .save ()
162
+ }
163
+ "
164
+ ` ;
165
+
166
+ exports [` Ethereum subgraph scaffolding > Mapping handles tuple array type conversion 1` ] = `
167
+ "import { BigInt , Bytes } from "@graphprotocol/graph-ts"
168
+ import {
169
+ Contract ,
170
+ ExampleEvent ,
171
+ ExampleEvent1 ,
172
+ TupleArrayEvent
173
+ } from "../generated/Contract/Contract"
174
+ import { ExampleEntity } from "../generated/schema"
175
+
176
+ export function handleExampleEvent(event: ExampleEvent): void {
177
+ // Entities can be loaded from the store using an ID; this ID
178
+ // needs to be unique across all entities of the same type
179
+ const id = event .transaction .hash .concat (
180
+ Bytes .fromByteArray (Bytes .fromBigInt (event .logIndex ))
181
+ )
182
+ let entity = ExampleEntity .load (id )
183
+
184
+ // Entities only exist after they have been saved to the store;
185
+ // \`null\` checks allow to create entities on demand
186
+ if (! entity ) {
187
+ entity = new ExampleEntity(id )
188
+
189
+ // Entity fields can be set using simple assignments
190
+ entity.count = BigInt.fromI32(0)
191
+ }
192
+
193
+ // BigInt and BigDecimal math are supported
194
+ entity .count = entity .count + BigInt .fromI32 (1 )
195
+
196
+ // Entity fields can be set based on event parameters
197
+ entity .a = event .params .a
198
+ entity .b = event .params .b
199
+
200
+ // Entities can be written to the store with \`.save()\`
201
+ entity .save ()
202
+
203
+ // Note: If a handler doesn't require existing field values, it is faster
204
+ // _not_ to load the entity from the store. Instead, create it fresh with
205
+ // \`new Entity(...)\`, set the fields that should be updated and save the
206
+ // entity back to the store. Fields that were not set or unset remain
207
+ // unchanged, allowing for partial updates to be applied.
208
+
209
+ // It is also possible to access smart contracts from mappings. For
210
+ // example, the contract that has emitted the event can be connected to
211
+ // with:
212
+ //
213
+ // let contract = Contract.bind(event.address)
214
+ //
215
+ // The following functions can then be called on this contract to access
216
+ // state variables and other data:
217
+ //
218
+ // - contract.someVariable(...)
219
+ // - contract.getSomeValue(...)
220
+ }
221
+
222
+ export function handleExampleEvent1(event: ExampleEvent1): void { }
223
+
224
+ export function handleTupleArrayEvent(event: TupleArrayEvent): void { }
137
225
"
138
226
` ;
139
227
@@ -173,6 +261,15 @@ type ExampleEvent1 @entity(immutable: true) {
173
261
blockTimestamp : BigInt !
174
262
transactionHash : Bytes !
175
263
}
264
+
265
+ type TupleArrayEvent @entity(immutable: true) {
266
+ id : Bytes !
267
+ tupleArray : [Bytes ! ]! # tuple []
268
+ addressArray : [Bytes ! ]! # address []
269
+ blockNumber : BigInt !
270
+ blockTimestamp : BigInt !
271
+ transactionHash : Bytes !
272
+ }
176
273
"
177
274
` ;
178
275
@@ -185,7 +282,7 @@ exports[`Ethereum subgraph scaffolding > Test Files (default) 1`] = `
185
282
beforeAll ,
186
283
afterAll
187
284
} from "matchstick-as/assembly/index"
188
- import { BigInt , Bytes } from "@graphprotocol/graph-ts"
285
+ import { BigInt , Bytes , Address } from "@graphprotocol/graph-ts"
189
286
import { ExampleEvent } from "../generated/schema"
190
287
import { ExampleEvent as ExampleEventEvent } from "../generated/Contract/Contract"
191
288
import { handleExampleEvent } from "../src/contract"
@@ -257,8 +354,12 @@ describe("Describe entity assertions", () => {
257
354
258
355
exports [` Ethereum subgraph scaffolding > Test Files (default) 2` ] = `
259
356
"import { newMockEvent } from "matchstick-as"
260
- import { ethereum , BigInt , Bytes } from "@graphprotocol/graph-ts"
261
- import { ExampleEvent , ExampleEvent1 } from "../generated/Contract/Contract"
357
+ import { ethereum , BigInt , Bytes , Address } from "@graphprotocol/graph-ts"
358
+ import {
359
+ ExampleEvent ,
360
+ ExampleEvent1 ,
361
+ TupleArrayEvent
362
+ } from "../generated/Contract/Contract"
262
363
263
364
export function createExampleEventEvent(
264
365
a: BigInt,
@@ -305,6 +406,30 @@ export function createExampleEvent1Event(a: Bytes): ExampleEvent1 {
305
406
306
407
return exampleEvent1Event
307
408
}
409
+
410
+ export function createTupleArrayEventEvent(
411
+ tupleArray: Array<ethereum.Tuple >,
412
+ addressArray: Array<Address >
413
+ ): TupleArrayEvent {
414
+ let tupleArrayEventEvent = changetype <TupleArrayEvent >(newMockEvent ())
415
+
416
+ tupleArrayEventEvent .parameters = new Array ()
417
+
418
+ tupleArrayEventEvent .parameters .push (
419
+ new ethereum .EventParam (
420
+ " tupleArray" ,
421
+ ethereum .Value .fromTupleArray (tupleArray )
422
+ )
423
+ )
424
+ tupleArrayEventEvent .parameters .push (
425
+ new ethereum .EventParam (
426
+ " addressArray" ,
427
+ ethereum .Value .fromAddressArray (addressArray )
428
+ )
429
+ )
430
+
431
+ return tupleArrayEventEvent
432
+ }
308
433
"
309
434
`;
310
435
@@ -317,7 +442,7 @@ exports[`Ethereum subgraph scaffolding > Test Files (for indexing events) 1`] =
317
442
beforeAll ,
318
443
afterAll
319
444
} from "matchstick-as/assembly/index"
320
- import { BigInt , Bytes } from "@graphprotocol/graph-ts"
445
+ import { BigInt , Bytes , Address } from "@graphprotocol/graph-ts"
321
446
import { ExampleEvent } from "../generated/schema"
322
447
import { ExampleEvent as ExampleEventEvent } from "../generated/Contract/Contract"
323
448
import { handleExampleEvent } from "../src/contract"
@@ -389,8 +514,12 @@ describe("Describe entity assertions", () => {
389
514
390
515
exports[`Ethereum subgraph scaffolding > Test Files (for indexing events) 2`] = `
391
516
"import { newMockEvent } from "matchstick-as"
392
- import { ethereum , BigInt , Bytes } from "@graphprotocol/graph-ts"
393
- import { ExampleEvent , ExampleEvent1 } from "../generated/Contract/Contract"
517
+ import { ethereum , BigInt , Bytes , Address } from "@graphprotocol/graph-ts"
518
+ import {
519
+ ExampleEvent ,
520
+ ExampleEvent1 ,
521
+ TupleArrayEvent
522
+ } from "../generated/Contract/Contract"
394
523
395
524
export function createExampleEventEvent(
396
525
a: BigInt,
@@ -437,5 +566,29 @@ export function createExampleEvent1Event(a: Bytes): ExampleEvent1 {
437
566
438
567
return exampleEvent1Event
439
568
}
569
+
570
+ export function createTupleArrayEventEvent(
571
+ tupleArray: Array<ethereum.Tuple >,
572
+ addressArray: Array<Address >
573
+ ): TupleArrayEvent {
574
+ let tupleArrayEventEvent = changetype <TupleArrayEvent >(newMockEvent ())
575
+
576
+ tupleArrayEventEvent .parameters = new Array ()
577
+
578
+ tupleArrayEventEvent .parameters .push (
579
+ new ethereum .EventParam (
580
+ " tupleArray" ,
581
+ ethereum .Value .fromTupleArray (tupleArray )
582
+ )
583
+ )
584
+ tupleArrayEventEvent .parameters .push (
585
+ new ethereum .EventParam (
586
+ " addressArray" ,
587
+ ethereum .Value .fromAddressArray (addressArray )
588
+ )
589
+ )
590
+
591
+ return tupleArrayEventEvent
592
+ }
440
593
"
441
594
`;
0 commit comments