Skip to content

Commit

Permalink
fix: schema metadata not linked and potential id collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Jan 23, 2024
1 parent 32bf62c commit 2f68c6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/mappings/ethereumDIDRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function handleDIDAttributeChanged(event: DIDAttributeChanged): void {
// called it directly, it could crash the subgraph
let hexHash = changetype<Bytes>(addQm(event.params.value))
let base58Hash = hexHash.toBase58()
let metadataId = graphAccount.id.concat('-').concat(base58Hash)
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
let metadataId = uniqueTxID.concat('-').concat(graphAccount.id.concat('-').concat(base58Hash))
graphAccount.metadata = metadataId
graphAccount.save()

Expand Down
15 changes: 10 additions & 5 deletions src/mappings/gns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ export function handleSubgraphMetadataUpdated(event: SubgraphMetadataUpdated): v

let hexHash = changetype<Bytes>(addQm(event.params.subgraphMetadata))
let base58Hash = hexHash.toBase58()
let metadataId = subgraph.id.concat('-').concat(base58Hash)
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
let metadataId = uniqueTxID.concat('-').concat(subgraph.id.concat('-').concat(base58Hash))
subgraph.metadataHash = event.params.subgraphMetadata
subgraph.metadata = metadataId
subgraph.updatedAt = event.block.timestamp.toI32()
Expand Down Expand Up @@ -237,7 +238,8 @@ export function handleSubgraphPublished(event: SubgraphPublished): void {
subgraphVersion.createdAt = event.block.timestamp.toI32()
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
let base58Hash = hexHash.toBase58()
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash))
subgraphVersion.metadataHash = event.params.versionMetadata
subgraphVersion.metadata = metadataId
subgraphVersion.save()
Expand Down Expand Up @@ -717,7 +719,8 @@ export function handleSubgraphMetadataUpdatedV2(event: SubgraphMetadataUpdated1)

let hexHash = changetype<Bytes>(addQm(event.params.subgraphMetadata))
let base58Hash = hexHash.toBase58()
let metadataId = subgraph.id.concat('-').concat(base58Hash)
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
let metadataId = uniqueTxID.concat('-').concat(subgraph.id.concat('-').concat(base58Hash))
subgraph.metadataHash = event.params.subgraphMetadata
subgraph.metadata = metadataId;
subgraph.updatedAt = event.block.timestamp.toI32()
Expand Down Expand Up @@ -1083,7 +1086,8 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
let subgraphVersion = SubgraphVersion.load(versionID)!
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
let base58Hash = hexHash.toBase58()
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash))
subgraphVersion.metadataHash = event.params.versionMetadata
subgraphVersion.metadata = metadataId
subgraphVersion.save()
Expand Down Expand Up @@ -1114,7 +1118,8 @@ export function handleSubgraphVersionUpdated(event: SubgraphVersionUpdated): voi
subgraphVersion.createdAt = event.block.timestamp.toI32()
let hexHash = changetype<Bytes>(addQm(event.params.versionMetadata))
let base58Hash = hexHash.toBase58()
let metadataId = subgraphVersion.id.concat('-').concat(base58Hash)
let uniqueTxID = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
let metadataId = uniqueTxID.concat('-').concat(subgraphVersion.id.concat('-').concat(base58Hash))
subgraphVersion.metadataHash = event.params.versionMetadata
subgraphVersion.metadata = metadataId

Expand Down
6 changes: 4 additions & 2 deletions src/mappings/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function handleSubgraphDeploymentSchema(content: Bytes): void {
}

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

let context = new DataSourceContext()
context.setString('id', subgraphDeploymentManifest.id.concat('-').concat(schemaIpfsHash))
context.setString('id', schemaId)
SubgraphDeploymentSchemaTemplate.createWithContext(schemaIpfsHash, context)
} else {
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()])
Expand Down

0 comments on commit 2f68c6f

Please sign in to comment.