Skip to content

Commit f4e5df6

Browse files
committed
Rename subgraph metadata json objects
1 parent 8d8227b commit f4e5df6

File tree

14 files changed

+156
-112
lines changed

14 files changed

+156
-112
lines changed

scripts/contracts/connectedContracts.ts

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import { connectContracts } from './connectedNetwork'
1414
import {
1515
SubgraphMetadata,
1616
AccountMetadata,
17+
VersionMetadata,
1718
jsonToAccountMetadata,
1819
jsonToSubgraphMetadata,
20+
jsonToVersionMetadata,
1921
} from '../metadataHelpers'
2022

2123
/**** connectedContracts.ts Description
@@ -206,31 +208,28 @@ class ConnectedGNS extends ConnectedContract {
206208
ipfs: string,
207209
graphAccount: string,
208210
subgraphDeploymentID: string,
209-
nameIdentifier: string,
210-
name: string,
211-
metadataPath: string | SubgraphMetadata,
211+
versionMetadata: string | SubgraphMetadata,
212+
subgraphMetadata: string | SubgraphMetadata,
212213
): Promise<ContractTransaction> => {
213-
const metaHashBytes = await this.handleSubgraphMetadata(ipfs, metadataPath)
214+
const subgraphDataHash = await this.handleSubgraphMetadata(ipfs, subgraphMetadata)
215+
const versionDataHash = await this.handleVersionMetadata(ipfs, versionMetadata)
214216
const subgraphDeploymentIDBytes = IPFS.ipfsHashToBytes32(subgraphDeploymentID)
215-
216217
return this.gns.publishNewSubgraph(
217218
graphAccount,
218219
subgraphDeploymentIDBytes,
219-
metaHashBytes,
220-
metaHashBytes, // Need to fix this so its version metadata
220+
versionDataHash,
221+
subgraphDataHash,
221222
)
222223
}
223224

224225
pinIPFSAndNewVersion = async (
225226
ipfs: string,
226227
graphAccount: string,
227228
subgraphDeploymentID: string,
228-
nameIdentifier: string,
229-
name: string,
230-
metadataPath: string | SubgraphMetadata,
229+
versionMetadata: string | SubgraphMetadata,
231230
subgraphNumber: string,
232231
): Promise<ContractTransaction> => {
233-
const metaHashBytes = await this.handleSubgraphMetadata(ipfs, metadataPath)
232+
const metaHashBytes = await this.handleVersionMetadata(ipfs, versionMetadata)
234233
const subgraphDeploymentIDBytes = IPFS.ipfsHashToBytes32(subgraphDeploymentID)
235234
return this.gns.publishNewVersion(
236235
graphAccount,
@@ -251,13 +250,42 @@ class ConnectedGNS extends ConnectedContract {
251250
))
252251
: (metadata = pathOrData)
253252
console.log('Meta data:')
254-
console.log(' Subgraph Description: ', metadata.subgraphDescription)
255-
console.log(' Subgraph Display Name: ', metadata.subgraphDisplayName)
256-
console.log(' Subgraph Image: ', metadata.subgraphImage)
257-
console.log(' Subgraph Code Repository: ', metadata.subgraphCodeRepository)
258-
console.log(' Subgraph Website: ', metadata.subgraphWebsite)
259-
console.log(' Version Description: ', metadata.versionDescription)
260-
console.log(' Version Label: ', metadata.versionLabel)
253+
console.log(' Subgraph Description: ', metadata.description)
254+
console.log(' Subgraph Display Name: ', metadata.displayName)
255+
console.log(' Subgraph Image: ', metadata.image)
256+
console.log(' Subgraph Code Repository: ', metadata.codeRepository)
257+
console.log(' Subgraph Website: ', metadata.website)
258+
259+
const ipfsClient = IPFS.createIpfsClient(ipfs)
260+
261+
console.log('\nUpload JSON meta data to IPFS...')
262+
const result = await ipfsClient.add(Buffer.from(JSON.stringify(metadata)))
263+
const metaHash = result[0].hash
264+
try {
265+
const data = JSON.parse(await ipfsClient.cat(metaHash))
266+
if (JSON.stringify(data) !== JSON.stringify(metadata)) {
267+
throw new Error(`Original meta data and uploaded data are not identical`)
268+
}
269+
} catch (e) {
270+
throw new Error(`Failed to retrieve and parse JSON meta data after uploading: ${e.message}`)
271+
}
272+
console.log(`Upload metadata successful: ${metaHash}\n`)
273+
return IPFS.ipfsHashToBytes32(metaHash)
274+
}
275+
276+
private handleVersionMetadata = async (
277+
ipfs: string,
278+
pathOrData: string | VersionMetadata,
279+
): Promise<string> => {
280+
let metadata: VersionMetadata
281+
typeof pathOrData == 'string'
282+
? (metadata = jsonToVersionMetadata(
283+
JSON.parse(fs.readFileSync(__dirname + pathOrData).toString()),
284+
))
285+
: (metadata = pathOrData)
286+
console.log('Meta data:')
287+
console.log(' Version Description: ', metadata.description)
288+
console.log(' Version Label: ', metadata.label)
261289

262290
const ipfsClient = IPFS.createIpfsClient(ipfs)
263291

scripts/contracts/gns.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ Usage: ${path.basename(process.argv[1])}
5252
--name <string> - name of the subgraph
5353
--metadataPath <path> - filepath to metadata. JSON format:
5454
{
55-
"subgraphDescription": "",
56-
"subgraphImage": "",
57-
"subgraphCodeRepository": "",
58-
"subgraphWebsite": "",
59-
"versionDescription": "",
60-
"versionLabel": ""
55+
"description": "",
56+
"image": "",
57+
"codeRepository": "",
58+
"website": "",
59+
"description": "",
60+
"label": ""
6161
}
6262
publishVersion
6363
--ipfs <url> - ex. https://api.thegraph.com/ipfs/

scripts/contracts/populateData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const populateENS = async (network: string, signers: Array<Wallet>) => {
9797
let i = 0
9898
for (const subgraph in subgraphMetadatas) {
9999
const ens = new ConnectedENS(network, signers[i])
100-
let name = subgraphMetadatas[subgraph].subgraphDisplayName
100+
let name = subgraphMetadatas[subgraph].displayName
101101
// edge case - graph is only ens name that doesn't match display name in mock data
102102
if (name == 'The Graph') name = 'graphprotocol'
103103
console.log(`Setting ${name} for ${ens.configuredWallet.address} on ens ...`)
@@ -116,7 +116,7 @@ const populateGNS = async (network: string, signers: Array<Wallet>) => {
116116
for (const subgraph in subgraphMetadatas) {
117117
const gns = new ConnectedGNS(network, signers[i])
118118
const ipfs = 'https://api.thegraph.com/ipfs/'
119-
let name = subgraphMetadatas[subgraph].subgraphDisplayName
119+
let name = subgraphMetadatas[subgraph].displayName
120120
// edge case - graph is only ens name that doesn't match display name in mock data
121121
if (name == 'The Graph') name = 'graphprotocol'
122122
const nameIdentifier = utils.namehash(`${name}.test`)

scripts/metadataHelpers.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,33 @@ interface AccountMetadata {
77
}
88

99
interface SubgraphMetadata {
10-
subgraphDescription: string
11-
subgraphDisplayName: string
12-
subgraphImage: string
13-
subgraphCodeRepository: string
14-
subgraphWebsite: string
15-
versionLabel: string
16-
versionDescription: string
10+
description: string
11+
displayName: string
12+
image: string
13+
codeRepository: string
14+
website: string
15+
}
16+
17+
interface VersionMetadata {
18+
label: string
19+
description: string
1720
}
1821

1922
const jsonToSubgraphMetadata = (json): SubgraphMetadata => {
2023
const subgraphMetadata: SubgraphMetadata = {
21-
subgraphDescription: checkString(json.subgraphDescription),
22-
subgraphDisplayName: checkString(json.subgraphDisplayName),
23-
subgraphImage: checkString(json.subgraphImage),
24-
subgraphCodeRepository: checkString(json.subgraphCodeRepository),
25-
subgraphWebsite: checkString(json.subgraphWebsite),
26-
versionLabel: checkString(json.versionLabel),
27-
versionDescription: checkString(json.versionDescription),
24+
description: checkString(json.description),
25+
displayName: checkString(json.displayName),
26+
image: checkString(json.image),
27+
codeRepository: checkString(json.codeRepository),
28+
website: checkString(json.website),
29+
}
30+
return subgraphMetadata
31+
}
32+
33+
const jsonToVersionMetadata = (json): VersionMetadata => {
34+
const subgraphMetadata: VersionMetadata = {
35+
label: checkString(json.label),
36+
description: checkString(json.description),
2837
}
2938
return subgraphMetadata
3039
}
@@ -47,4 +56,11 @@ const checkString = (field): string => {
4756
return field
4857
}
4958

50-
export { AccountMetadata, SubgraphMetadata, jsonToSubgraphMetadata, jsonToAccountMetadata }
59+
export {
60+
AccountMetadata,
61+
SubgraphMetadata,
62+
VersionMetadata,
63+
jsonToSubgraphMetadata,
64+
jsonToVersionMetadata,
65+
jsonToAccountMetadata,
66+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"subgraphDescription": "Compound is an open-source protocol for algorithmic, efficient Money Markets on the Ethereum blockchain.",
3-
"subgraphDisplayName": "Compound",
4-
"subgraphImage": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmeMR3qK7wfAuSns4PpdFVZZcsCoLa7wEPQbrZTBQNKGWq",
5-
"subgraphCodeRepository": "https://github.com/graphprotocol/compound-V2-subgraph",
6-
"subgraphWebsite": "https://compound.finance/",
7-
"versionLabel": "v0.1.0",
8-
"versionDescription": "First Version"
2+
"description": "Compound is an open-source protocol for algorithmic, efficient Money Markets on the Ethereum blockchain.",
3+
"displayName": "Compound",
4+
"image": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmeMR3qK7wfAuSns4PpdFVZZcsCoLa7wEPQbrZTBQNKGWq",
5+
"codeRepository": "https://github.com/graphprotocol/compound-V2-subgraph",
6+
"website": "https://compound.finance/",
7+
"label": "v0.1.0",
8+
"description": "First Version"
99
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"subgraphDescription": "A decentralized virtual world that runs on open standards. Find districts, parcels, auctions, and more.",
3-
"subgraphDisplayName": "Decentraland",
4-
"subgraphImage": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmVMtgVvEJLqmH3PZzcYVp5t8ni1v61e2M1rDVkcRo9WCz",
5-
"subgraphCodeRepository": "https://github.com/graphprotocol/decentraland-subgraph",
6-
"subgraphWebsite": "https://decentraland.org/",
7-
"versionLabel": "v0.1.0",
8-
"versionDescription": "First Version"
2+
"description": "A decentralized virtual world that runs on open standards. Find districts, parcels, auctions, and more.",
3+
"displayName": "Decentraland",
4+
"image": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmVMtgVvEJLqmH3PZzcYVp5t8ni1v61e2M1rDVkcRo9WCz",
5+
"codeRepository": "https://github.com/graphprotocol/decentraland-subgraph",
6+
"website": "https://decentraland.org/",
7+
"label": "v0.1.0",
8+
"description": "First Version"
99
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"subgraphDescription": "A secure & decentralized way to address resources on and off the blockchain using simple, human-readable names. Access domains and transfer history.",
3-
"subgraphDisplayName": "ENS",
4-
"subgraphImage": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmUqD4MMAXQvbNX3FbWNP43gmDFFdQPmQrn8CT9kNEb7Rs",
5-
"subgraphCodeRepository": "https://github.com/ensdomains/ens-subgraph",
6-
"subgraphWebsite": "https://ens.domains/",
7-
"versionLabel": "v0.1.0",
8-
"versionDescription": "First Version"
2+
"description": "A secure & decentralized way to address resources on and off the blockchain using simple, human-readable names. Access domains and transfer history.",
3+
"displayName": "ENS",
4+
"image": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmUqD4MMAXQvbNX3FbWNP43gmDFFdQPmQrn8CT9kNEb7Rs",
5+
"codeRepository": "https://github.com/ensdomains/ens-subgraph",
6+
"website": "https://ens.domains/",
7+
"label": "v0.1.0",
8+
"description": "First Version"
99
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"subgraphDescription": "A protocol for affordable and reliable video encoding. Find transcoders, staking rounds, and rewards.",
3-
"subgraphDisplayName": "Livepeer",
4-
"subgraphImage": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmcTyMcTpkSrRs8Q7tUBPqA6ektwL7x5DEZCsEpoveXxe1",
5-
"subgraphCodeRepository": "https://github.com/livepeer/livepeerjs/tree/master/packages/subgraph",
6-
"subgraphWebsite": "https://livepeer.org/",
7-
"versionLabel": "v0.1.0",
8-
"versionDescription": "First Version"
2+
"description": "A protocol for affordable and reliable video encoding. Find transcoders, staking rounds, and rewards.",
3+
"displayName": "Livepeer",
4+
"image": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmcTyMcTpkSrRs8Q7tUBPqA6ektwL7x5DEZCsEpoveXxe1",
5+
"codeRepository": "https://github.com/livepeer/livepeerjs/tree/master/packages/subgraph",
6+
"website": "https://livepeer.org/",
7+
"label": "v0.1.0",
8+
"description": "First Version"
99
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"subgraphDescription": "Maker is a protocol for collateralized stable coin creation.",
3-
"subgraphDisplayName": "Maker",
4-
"subgraphImage": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmdJ2g7fbk1XDh24NBCwWNSUZ8jY1XxpG9ukXhLAhanP6C",
5-
"subgraphCodeRepository": "https://github.com/makerdao",
6-
"subgraphWebsite": "https://makerdao.com/en/",
7-
"versionLabel": "v0.1.0",
8-
"versionDescription": "First Version"
2+
"description": "Maker is a protocol for collateralized stable coin creation.",
3+
"displayName": "Maker",
4+
"image": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmdJ2g7fbk1XDh24NBCwWNSUZ8jY1XxpG9ukXhLAhanP6C",
5+
"codeRepository": "https://github.com/makerdao",
6+
"website": "https://makerdao.com/en/",
7+
"label": "v0.1.0",
8+
"description": "First Version"
99
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"subgraphDescription": "Technology operated and regulated funds.",
3-
"subgraphDisplayName": "Melon",
4-
"subgraphImage": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmQpuowYwm5c7XYXmEbSGsP6EqTU7vEWBJGN3NhJLQZ7wq",
5-
"subgraphCodeRepository": "https://github.com/melonproject/melon-subgraph",
6-
"subgraphWebsite": "https://melonport.com",
7-
"versionLabel": "v0.1.0",
8-
"versionDescription": "First Version"
2+
"description": "Technology operated and regulated funds.",
3+
"displayName": "Melon",
4+
"image": "https://api.thegraph.com/ipfs/api/v0/cat?arg=QmQpuowYwm5c7XYXmEbSGsP6EqTU7vEWBJGN3NhJLQZ7wq",
5+
"codeRepository": "https://github.com/melonproject/melon-subgraph",
6+
"website": "https://melonport.com",
7+
"label": "v0.1.0",
8+
"description": "First Version"
99
}

0 commit comments

Comments
 (0)