File tree Expand file tree Collapse file tree 4 files changed +18
-8
lines changed
protocols/ethereum/scaffold Expand file tree Collapse file tree 4 files changed +18
-8
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @graphprotocol/graph-cli ' : patch
3
+ ---
4
+
5
+ fix generated example entity id uniqueness
Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ packages/cli/tests/cli/add
8
8
packages /cli /config /TheGraphNetworksRegistry.json
9
9
pnpm-lock.yaml
10
10
website /src /graphql-env.d.ts
11
+ renovate.json
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export const generatePlaceholderHandlers = ({
11
11
contractName : string ;
12
12
} ) =>
13
13
`
14
- import { BigInt } from '@graphprotocol/graph-ts'
14
+ import { BigInt, Bytes } from '@graphprotocol/graph-ts'
15
15
import { ${ contractName } , ${ events . map ( event => event . _alias ) } }
16
16
from '../generated/${ contractName } /${ contractName } '
17
17
import { ExampleEntity } from '../generated/schema'
@@ -21,14 +21,15 @@ export const generatePlaceholderHandlers = ({
21
21
index === 0
22
22
? `
23
23
export function handle${ event . _alias } (event: ${ event . _alias } ): void {
24
- // Entities can be loaded from the store using a string ID; this ID
24
+ // Entities can be loaded from the store using an ID; this ID
25
25
// needs to be unique across all entities of the same type
26
- let entity = ExampleEntity.load(event.transaction.from)
26
+ const id = event.transaction.hash.concat(Bytes.fromByteArray(Bytes.fromBigInt(event.logIndex)));
27
+ let entity = ExampleEntity.load(id)
27
28
28
29
// Entities only exist after they have been saved to the store;
29
30
// \`null\` checks allow to create entities on demand
30
31
if (!entity) {
31
- entity = new ExampleEntity(event.transaction.from )
32
+ entity = new ExampleEntity(id )
32
33
33
34
// Entity fields can be set using simple assignments
34
35
entity.count = BigInt.fromI32(0)
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ dataSources:
34
34
` ;
35
35
36
36
exports [` Ethereum subgraph scaffolding > Mapping (default) 1` ] = `
37
- "import { BigInt } from "@graphprotocol/graph-ts"
37
+ "import { BigInt , Bytes } from "@graphprotocol/graph-ts"
38
38
import {
39
39
Contract ,
40
40
ExampleEvent ,
@@ -43,14 +43,17 @@ import {
43
43
import { ExampleEntity } from "../generated/schema"
44
44
45
45
export function handleExampleEvent(event: ExampleEvent): void {
46
- // Entities can be loaded from the store using a string ID; this ID
46
+ // Entities can be loaded from the store using an ID; this ID
47
47
// needs to be unique across all entities of the same type
48
- let entity = ExampleEntity .load (event .transaction .from )
48
+ const id = event .transaction .hash .concat (
49
+ Bytes .fromByteArray (Bytes .fromBigInt (event .logIndex ))
50
+ )
51
+ let entity = ExampleEntity .load (id )
49
52
50
53
// Entities only exist after they have been saved to the store;
51
54
// \`null\` checks allow to create entities on demand
52
55
if (! entity ) {
53
- entity = new ExampleEntity(event . transaction . from )
56
+ entity = new ExampleEntity(id )
54
57
55
58
// Entity fields can be set using simple assignments
56
59
entity.count = BigInt.fromI32(0)
You can’t perform that action at this time.
0 commit comments