Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync mainnet staging (FDS refactor) #35

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-arbitrum-goerli-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-goerli-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-production-arbitrum-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-production-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging-arbitrum-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging-subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
node-version: '20'
registry-url: https://registry.npmjs.org
- name: yarn add ts-node
run: yarn add ts-node
Expand Down
44 changes: 23 additions & 21 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,8 @@ type GraphAccount @entity {
"Default display name is the current default name. Used for filtered queries in the explorer"
defaultDisplayName: String

# # IPFS Metadata
"True if it is an organization. False if it is an individual"
isOrganization: Boolean

"IPFS hash with account metadata details"
metadataHash: Bytes

"Main repository of code for the graph account"
codeRepository: String

"Description of the graph account"
description: String

"Image URL"
image: String

"Website URL"
website: String

"Display name. Not unique"
displayName: String
# IPFS Metadata.
metadata: GraphAccountMetadata

# Operator info
"Operator of other Graph Accounts"
Expand Down Expand Up @@ -171,6 +152,27 @@ type GraphAccount @entity {
nameSignalTransactions: [NameSignalTransaction!]! @derivedFrom(field: "signer")
}

type GraphAccountMetadata @entity(immutable:true) {
"IPFS hash with account metadata details"
id: ID!
"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"
codeRepository: String
"Description of the graph account"
description: String
"Image URL"
image: String
"Website URL"
website: String
"Display name. Not unique"
displayName: String
}

"""
A name chosen by a Graph Account from a Name System such as ENS. This allows Graph Accounts to be
recognized by name, rather than just an Ethereum address
Expand Down
34 changes: 11 additions & 23 deletions src/mappings/ethereumDIDRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { json, ipfs, Bytes, JSONValueKind } 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'

import { addQm, createOrLoadGraphAccount } from './helpers'
import { jsonToString } from './utils'

export function handleDIDAttributeChanged(event: DIDAttributeChanged): void {
let id = event.params.identity.toHexString()
let graphAccount = createOrLoadGraphAccount(id, event.block.timestamp)
let graphAccount = createOrLoadGraphAccount(event.params.identity.toHexString(), event.block.timestamp)
// OFFCHAIN_DATANAME = keccak256("GRAPH NAME SERVICE")
// 0x72abcb436eed911d1b6046bbe645c235ec3767c842eb1005a6da9326c2347e4c
if (
Expand All @@ -17,24 +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.metadataHash = event.params.value
let metadataId = graphAccount.id.concat('-').concat(base58Hash)
graphAccount.metadata = metadataId
graphAccount.save()

let ipfsData = ipfs.cat(base58Hash)
if (ipfsData !== null) {
let tryData = json.try_fromBytes(ipfsData as Bytes)
if (tryData.isOk) {
let data = tryData.value.toObject()
graphAccount.codeRepository = jsonToString(data.get('codeRepository'))
graphAccount.description = jsonToString(data.get('description'))
graphAccount.image = jsonToString(data.get('image'))
graphAccount.displayName = jsonToString(data.get('displayName'))
let isOrganization = data.get('isOrganization')
if (isOrganization != null && isOrganization.kind === JSONValueKind.BOOL) {
graphAccount.isOrganization = isOrganization.toBool()
}
graphAccount.website = jsonToString(data.get('website'))
graphAccount.save()
}
}
let context = new DataSourceContext()
context.setString('id', metadataId)
GraphAccountMetadataTemplate.createWithContext(base58Hash, context)
}
}
}
24 changes: 24 additions & 0 deletions src/mappings/ipfs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { json, Bytes, dataSource, JSONValueKind, log } from '@graphprotocol/graph-ts'
import {
GraphAccountMetadata
} from '../types/schema'
import { jsonToString } from './utils'

export function handleGraphAccountMetadata(content: Bytes): void {
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()
graphAccountMetadata.codeRepository = jsonToString(data.get('codeRepository'))
graphAccountMetadata.description = jsonToString(data.get('description'))
graphAccountMetadata.image = jsonToString(data.get('image'))
graphAccountMetadata.displayName = jsonToString(data.get('displayName'))
let isOrganization = data.get('isOrganization')
if (isOrganization != null && isOrganization.kind === JSONValueKind.BOOL) {
graphAccountMetadata.isOrganization = isOrganization.toBool()
}
graphAccountMetadata.website = jsonToString(data.get('website'))
graphAccountMetadata.save()
}
}
14 changes: 13 additions & 1 deletion subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ description: Graph Network analytics subgraph
repository: https://github.com/graphprotocol/graph-network-analytics-subgraph
features:
- fullTextSearch
- ipfsOnEthereumContracts
schema:
file: ./schema.graphql
dataSources:
Expand Down Expand Up @@ -450,3 +449,16 @@ dataSources:
# handler: handleImplementationUpdated
# - event: ParameterUpdated(string)
# handler: handleParameterUpdated
templates:
- name: GraphAccountMetadata
kind: file/ipfs
mapping:
apiVersion: 0.0.7
language: wasm/assemblyscript
file: ./src/mappings/ipfs.ts
handler: handleGraphAccountMetadata
entities:
- GraphAccountMetadata
abis:
- name: EpochManager
file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json
Loading
Loading