Skip to content

Commit

Permalink
fix: futureproofing duplicate ID for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Jan 23, 2024
1 parent 9f90773 commit 0028a4b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ type GraphAccount @entity {
type GraphAccountMetadata @entity(immutable:true) {
"IPFS hash with account metadata details"
id: ID!
"Original graph account that created it"
graphAccount: [GraphAccount!] @derivedFrom(field:"metadata")
"Account that reference this metadata file. For compatibility purposes. For the full list use graphAccounts"
graphAccount: GraphAccount @derivedFrom(field:"metadata")
"Accounts that reference this metadata file"
graphAccounts: [GraphAccount!]! @derivedFrom(field:"metadata")
"True if it is an organization. False if it is an individual"
isOrganization: Boolean
"Main repository of code for the graph account"
Expand Down
9 changes: 6 additions & 3 deletions src/mappings/ethereumDIDRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bytes } from '@graphprotocol/graph-ts'
import { Bytes, DataSourceContext } from '@graphprotocol/graph-ts'
import { DIDAttributeChanged } from '../types/EthereumDIDRegistry/EthereumDIDRegistry'
import { GraphAccountMetadata as GraphAccountMetadataTemplate } from '../types/templates'
import { GraphAccount } from '../types/schema'
Expand All @@ -17,9 +17,12 @@ 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()
graphAccount.metadata = base58Hash
let metadataId = graphAccount.id.concat('-').concat(base58Hash)
graphAccount.metadata = metadataId
graphAccount.save()

GraphAccountMetadataTemplate.create(base58Hash)
let context = new DataSourceContext()
context.setString('id', metadataId)
GraphAccountMetadataTemplate.createWithContext(base58Hash, context)
}
}
3 changes: 2 additions & 1 deletion src/mappings/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
import { jsonToString } from './utils'

export function handleGraphAccountMetadata(content: Bytes): void {
let graphAccountMetadata = new GraphAccountMetadata(dataSource.stringParam())
let id = dataSource.context().getString("id")
let graphAccountMetadata = new GraphAccountMetadata(id)
let tryData = json.try_fromBytes(content)
if (tryData.isOk) {
let data = tryData.value.toObject()
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@
graphql-import-node "^0.0.5"
js-yaml "^4.1.0"

"@graphprotocol/contracts@5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@graphprotocol/contracts/-/contracts-5.3.0.tgz#9c754cdba56bf84ef32c68617dc59a4ddf00ffd0"
integrity sha512-o1Dvk1h+Me+BEaeYoPr4M2dBT5PvLJAUlSuKjIOIy/hD5y1PAkBMZi2EnP5BWXP+1vn4y3q7d+qZjAmVKakL/Q==
"@graphprotocol/contracts@5.3.3":
version "5.3.3"
resolved "https://registry.yarnpkg.com/@graphprotocol/contracts/-/contracts-5.3.3.tgz#89c383ce244d9ed6cf1146baafde379cbbdfdfe6"
integrity sha512-fmFSKr+VDinWWotj2q/Ztn92PppcRrYXeO/62gLgkLos/DcYa7bGWKbcOWyMUw0vsUvXxk6QAtr5o/LG3yQ1WQ==
dependencies:
console-table-printer "^2.11.1"
ethers "^5.6.0"
Expand Down

0 comments on commit 0028a4b

Please sign in to comment.