@@ -121,7 +121,7 @@ dataSources:
121
121
test ( 'Schema (default)' , ( ) => {
122
122
expect ( scaffold . generateSchema ( ) ) . toEqual ( `\
123
123
type ExampleEntity @entity {
124
- id: ID !
124
+ id: Bytes !
125
125
count: BigInt!
126
126
a: BigInt! # uint256
127
127
b: [Bytes]! # bytes[4]
@@ -131,8 +131,10 @@ type ExampleEntity @entity {
131
131
132
132
test ( 'Schema (for indexing events)' , ( ) => {
133
133
expect ( scaffoldWithIndexEvents . generateSchema ( ) ) . toEqual ( `\
134
- type ExampleEvent @entity {
135
- id: ID!
134
+ type ExampleEvent @entity(immutable: true) {
135
+ id: Bytes!
136
+
137
+ # Event params
136
138
a: BigInt! # uint256
137
139
b: [Bytes]! # bytes[4]
138
140
param2: String! # string
@@ -143,11 +145,27 @@ type ExampleEvent @entity {
143
145
c_c3_value1: String! # string
144
146
c_c3_value2: Bytes! # bytes32
145
147
d: String! # string
148
+
149
+ # Block & transaction info
150
+ blockNumber: BigInt!
151
+ blockHash: Bytes!
152
+ blockTimestamp: BigInt!
153
+ transactionHash: Bytes!
154
+ logIndex: BigInt!
146
155
}
147
156
148
- type ExampleEvent1 @entity {
149
- id: ID!
157
+ type ExampleEvent1 @entity(immutable: true) {
158
+ id: Bytes!
159
+
160
+ # Event params
150
161
a: Bytes! # bytes32
162
+
163
+ # Block & transaction info
164
+ blockNumber: BigInt!
165
+ blockHash: Bytes!
166
+ blockTimestamp: BigInt!
167
+ transactionHash: Bytes!
168
+ logIndex: BigInt!
151
169
}
152
170
` )
153
171
} )
@@ -165,12 +183,12 @@ import { ExampleEntity } from "../generated/schema"
165
183
export function handleExampleEvent(event: ExampleEvent): void {
166
184
// Entities can be loaded from the store using a string ID; this ID
167
185
// needs to be unique across all entities of the same type
168
- let entity = ExampleEntity.load(event.transaction.from.toHex() )
186
+ let entity = ExampleEntity.load(event.transaction.from)
169
187
170
188
// Entities only exist after they have been saved to the store;
171
189
// \`null\` checks allow to create entities on demand
172
190
if (!entity) {
173
- entity = new ExampleEntity(event.transaction.from.toHex() )
191
+ entity = new ExampleEntity(event.transaction.from)
174
192
175
193
// Entity fields can be set using simple assignments
176
194
entity.count = BigInt.fromI32(0)
@@ -219,7 +237,7 @@ import { ExampleEvent, ExampleEvent1 } from "../generated/schema"
219
237
220
238
export function handleExampleEvent(event: ExampleEventEvent): void {
221
239
let entity = new ExampleEvent(
222
- event.transaction.hash.toHex() + "-" + event.logIndex.toString()
240
+ event.transaction.hash.concatI32( event.logIndex.toI32()),
223
241
)
224
242
entity.a = event.params.a
225
243
entity.b = event.params.b
@@ -231,14 +249,28 @@ export function handleExampleEvent(event: ExampleEventEvent): void {
231
249
entity.c_c3_value1 = event.params.c.c3.value1
232
250
entity.c_c3_value2 = event.params.c.c3.value2
233
251
entity.d = event.params.d
252
+
253
+ entity.blockNumber = event.block.number
254
+ entity.blockHash = event.block.hash
255
+ entity.blockTimestamp = event.block.timestamp
256
+ entity.transactionHash = event.transaction.hash
257
+ entity.logIndex = event.logIndex
258
+
234
259
entity.save()
235
260
}
236
261
237
262
export function handleExampleEvent1(event: ExampleEvent1Event): void {
238
263
let entity = new ExampleEvent1(
239
- event.transaction.hash.toHex() + "-" + event.logIndex.toString()
264
+ event.transaction.hash.concatI32( event.logIndex.toI32()),
240
265
)
241
266
entity.a = event.params.a
267
+
268
+ entity.blockNumber = event.block.number
269
+ entity.blockHash = event.block.hash
270
+ entity.blockTimestamp = event.block.timestamp
271
+ entity.transactionHash = event.transaction.hash
272
+ entity.logIndex = event.logIndex
273
+
242
274
entity.save()
243
275
}
244
276
` )
0 commit comments