File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed
protocols/ethereum/scaffold Expand file tree Collapse file tree 3 files changed +17
-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 @@ -11,7 +11,7 @@ export const generatePlaceholderHandlers = ({
1111 contractName : string ;
1212} ) =>
1313 `
14- import { BigInt } from '@graphprotocol/graph-ts'
14+ import { BigInt, Bytes } from '@graphprotocol/graph-ts'
1515 import { ${ contractName } , ${ events . map ( event => event . _alias ) } }
1616 from '../generated/${ contractName } /${ contractName } '
1717 import { ExampleEntity } from '../generated/schema'
@@ -21,14 +21,15 @@ export const generatePlaceholderHandlers = ({
2121 index === 0
2222 ? `
2323 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
2525 // 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)
2728
2829 // Entities only exist after they have been saved to the store;
2930 // \`null\` checks allow to create entities on demand
3031 if (!entity) {
31- entity = new ExampleEntity(event.transaction.from )
32+ entity = new ExampleEntity(id )
3233
3334 // Entity fields can be set using simple assignments
3435 entity.count = BigInt.fromI32(0)
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ dataSources:
3434` ;
3535
3636exports [` Ethereum subgraph scaffolding > Mapping (default) 1` ] = `
37- "import { BigInt } from "@graphprotocol/graph-ts"
37+ "import { BigInt , Bytes } from "@graphprotocol/graph-ts"
3838import {
3939 Contract ,
4040 ExampleEvent ,
@@ -43,14 +43,17 @@ import {
4343import { ExampleEntity } from "../generated/schema"
4444
4545export 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
4747 // 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 )
4952
5053 // Entities only exist after they have been saved to the store;
5154 // \`null\` checks allow to create entities on demand
5255 if (! entity ) {
53- entity = new ExampleEntity(event . transaction . from )
56+ entity = new ExampleEntity(id )
5457
5558 // Entity fields can be set using simple assignments
5659 entity.count = BigInt.fromI32(0)
You can’t perform that action at this time.
0 commit comments