Skip to content

Commit 2f68c6f

Browse files
committed
fix: schema metadata not linked and potential id collisions
1 parent 32bf62c commit 2f68c6f

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/mappings/ethereumDIDRegistry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void {
1717
// called it directly, it could crash the subgraph
1818
let hexHash = changetype<Bytes>(addQm(event.params.value))
1919
let base58Hash = hexHash.toBase58()
20-
let metadataId = graphAccount.id.concat('-').concat(base58Hash)
20+
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
21+
let metadataId = uniqueTxID.concat('-').concat(graphAccount.id.concat('-').concat(base58Hash))
2122
graphAccount.metadata = metadataId
2223
graphAccount.save()
2324

src/mappings/gns.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v
179179

180180
let hexHash = changetype<Bytes>(addQm(event.params.subgraphMetadata))
181181
let base58Hash = hexHash.toBase58()
182-
let metadataId = subgraph.id.concat('-').concat(base58Hash)
182+
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
183+
let metadataId = uniqueTxID.concat('-').concat(subgraph.id.concat('-').concat(base58Hash))
183184
subgraph.metadataHash = event.params.subgraphMetadata
184185
subgraph.metadata = metadataId
185186
subgraph.updatedAt = event.block.timestamp.toI32()
@@ -237,7 +238,8 @@ export function handleSubgraphPublished(event: SubgraphPublished): void {
237238
subgraphVersion.createdAt = event.block.timestamp.toI32()
238239
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
239240
let base58Hash = hexHash.toBase58()
240-
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
241+
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
242+
let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash))
241243
subgraphVersion.metadataHash = event.params.versionMetadata
242244
subgraphVersion.metadata = metadataId
243245
subgraphVersion.save()
@@ -717,7 +719,8 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1)
717719

718720
let hexHash = changetype<Bytes>(addQm(event.params.subgraphMetadata))
719721
let base58Hash = hexHash.toBase58()
720-
let metadataId = subgraph.id.concat('-').concat(base58Hash)
722+
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
723+
let metadataId = uniqueTxID.concat('-').concat(subgraph.id.concat('-').concat(base58Hash))
721724
subgraph.metadataHash = event.params.subgraphMetadata
722725
subgraph.metadata = metadataId;
723726
subgraph.updatedAt = event.block.timestamp.toI32()
@@ -1083,7 +1086,8 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
10831086
let subgraphVersion = SubgraphVersion.load(versionID)!
10841087
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
10851088
let base58Hash = hexHash.toBase58()
1086-
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
1089+
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
1090+
let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash))
10871091
subgraphVersion.metadataHash = event.params.versionMetadata
10881092
subgraphVersion.metadata = metadataId
10891093
subgraphVersion.save()
@@ -1114,7 +1118,8 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
11141118
subgraphVersion.createdAt = event.block.timestamp.toI32()
11151119
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
11161120
let base58Hash = hexHash.toBase58()
1117-
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
1121+
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
1122+
let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash))
11181123
subgraphVersion.metadataHash = event.params.versionMetadata
11191124
subgraphVersion.metadata = metadataId
11201125

src/mappings/ipfs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export function handleSubgraphDeploymentSchema(content: Bytes): void {
8181
}
8282

8383
export function handleSubgraphDeploymentManifest(content: Bytes): void {
84+
// Shouldn't need ID since the handler isn't gonna be called more than once, given that it's only on deployment creation.
8485
let subgraphDeploymentManifest = new SubgraphDeploymentManifest(dataSource.stringParam())
8586
if (content !== null) {
8687
subgraphDeploymentManifest.manifest = content.toString()
@@ -98,11 +99,12 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void {
9899
let schemaIpfsHashTry = schemaFileSplit.split('\n', 2)
99100
if (schemaIpfsHashTry.length == 2) {
100101
let schemaIpfsHash = schemaIpfsHashTry[0]
101-
subgraphDeploymentManifest.schema = schemaIpfsHash
102+
let schemaId = subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash)
103+
subgraphDeploymentManifest.schema = schemaId
102104
subgraphDeploymentManifest.schemaIpfsHash = schemaIpfsHash
103105

104106
let context = new DataSourceContext()
105-
context.setString('id', subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash))
107+
context.setString('id', schemaId)
106108
SubgraphDeploymentSchemaTemplate.createWithContext(schemaIpfsHash, context)
107109
} else {
108110
log.warning("[MANIFEST PARSING FAIL] subgraphDeploymentManifest: {}, schema file hash can't be retrieved. Error: schemaIpfsHashTry.length isn't 2, actual length: {}", [dataSource.stringParam(), schemaIpfsHashTry.length.toString()])

0 commit comments

Comments
 (0)