From 01adecc9fb8157cad2e08ea5ea4b2552f259712d Mon Sep 17 00:00:00 2001 From: Juan Manuel Rodriguez Defago Date: Thu, 29 Jul 2021 19:45:17 -0300 Subject: [PATCH] Deleted untracked file --- src/mappings/metadataHelpers.ts | 91 --------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 src/mappings/metadataHelpers.ts diff --git a/src/mappings/metadataHelpers.ts b/src/mappings/metadataHelpers.ts deleted file mode 100644 index 2e1e380c..00000000 --- a/src/mappings/metadataHelpers.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { json, ipfs, Bytes, JSONValueKind, log } from '@graphprotocol/graph-ts' -import { GraphAccount, Subgraph, SubgraphVersion, SubgraphDeployment } from '../types/schema' -import { jsonToString } from './utils' -import { createOrLoadSubgraphCategory, createOrLoadSubgraphCategoryRelation, createOrLoadNetwork } from './helpers' - -export function fetchGraphAccountMetadata(graphAccount: GraphAccount, ipfsHash: string): void { - let ipfsData = ipfs.cat(ipfsHash) - if (ipfsData != null) { - let data = json.fromBytes(ipfsData as Bytes).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() - } -} - -export function fetchSubgraphMetadata(subgraph: Subgraph, ipfsHash: string): Subgraph { - let metadata = ipfs.cat(ipfsHash) - if (metadata !== null) { - let tryData = json.try_fromBytes(metadata as Bytes) - if (tryData.isOk) { - let data = tryData.value.toObject() - subgraph.description = jsonToString(data.get('description')) - subgraph.image = jsonToString(data.get('image')) - subgraph.displayName = jsonToString(data.get('displayName')) - subgraph.codeRepository = jsonToString(data.get('codeRepository')) - subgraph.website = jsonToString(data.get('website')) - let categories = data.get('categories') - - if(categories != null) { - let categoriesArray = categories.toArray() - - for(let i = 0; i < categoriesArray.length; i++) { - let categoryId = jsonToString(categoriesArray[i]) - createOrLoadSubgraphCategory(categoryId) - createOrLoadSubgraphCategoryRelation(categoryId, subgraph.id) - } - } - } - } - return subgraph -} - -export function fetchSubgraphVersionMetadata(subgraphVersion: SubgraphVersion, ipfsHash: string): SubgraphVersion { - let getVersionDataFromIPFS = ipfs.cat(ipfsHash) - if (getVersionDataFromIPFS !== null) { - let tryData = json.try_fromBytes(getVersionDataFromIPFS as Bytes) - if (tryData.isOk) { - let data = tryData.value.toObject() - subgraphVersion.description = jsonToString(data.get('description')) - subgraphVersion.label = jsonToString(data.get('label')) - } else { - subgraphVersion.description = '' - subgraphVersion.label = '' - } - } - return subgraphVersion -} - -export function fetchSubgraphDeploymentManifest(deployment: SubgraphDeployment, ipfsHash: string): SubgraphDeployment { - let getManifestFromIPFS = ipfs.cat(ipfsHash) - if (getManifestFromIPFS !== null) { - deployment.manifest = getManifestFromIPFS.toString() - - let manifest = deployment.manifest - // we take the right side of the split, since it's the one which will have the schema ipfs hash - let schemaSplit = manifest.split('schema:\n', 2)[1] - let schemaFileSplit = schemaSplit.split('/ipfs/', 2)[1] - let schemaIpfsHash = schemaFileSplit.split('\n', 2)[0] - deployment.schemaIpfsHash = schemaIpfsHash - - let getSchemaFromIPFS = ipfs.cat(schemaIpfsHash) - if (getSchemaFromIPFS !== null) { - deployment.schema = getSchemaFromIPFS.toString() - } - - // We get the first occurrence of `network` since subgraphs can only have data sources for the same network - let networkSplit = manifest.split('network: ', 2)[1] - let network = networkSplit.split('\n', 2)[0] - - createOrLoadNetwork(network) - deployment.network = network - } - return deployment as SubgraphDeployment -}