Skip to content

Commit d212878

Browse files
authored
Merge pull request #783 from graphprotocol/otavio/near-init
graph init for NEAR
2 parents a06b593 + 0729952 commit d212878

40 files changed

+1192
-708
lines changed

src/codegen/types/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ const findInitializationForType = (fromTypeSystem, toTypeSystem, ascType) => {
8989

9090
// High-level type system API
9191

92+
const ascTypeForProtocol = (protocol, protocolType) =>
93+
findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn(['to', 'type'])
94+
95+
// TODO: this can be removed/replaced by the function above
9296
const ascTypeForEthereum = ethereumType =>
93-
findConversionFromType('ethereum', 'AssemblyScript', ethereumType).getIn(['to', 'type'])
97+
ascTypeForProtocol('ethereum', ethereumType)
9498

9599
const ethereumTypeForAsc = ascType =>
96100
findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn(['to', 'type'])
@@ -120,6 +124,9 @@ const initializedValueFromAsc = ascType =>
120124
findInitializationForType('AssemblyScript', 'Value', ascType)
121125

122126
module.exports = {
127+
// protocol <-> AssemblyScript
128+
ascTypeForProtocol,
129+
123130
// ethereum <-> AssemblyScript
124131
ascTypeForEthereum,
125132
ethereumTypeForAsc,

src/command-helpers/scaffold.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const fs = require('fs-extra')
2+
const path = require('path')
3+
4+
const { step } = require('./spinner')
5+
const Scaffold = require('../scaffold')
6+
7+
const generateScaffold = async (
8+
{
9+
protocolInstance,
10+
abi,
11+
contract,
12+
network,
13+
subgraphName,
14+
indexEvents,
15+
contractName = 'Contract',
16+
node,
17+
},
18+
spinner,
19+
) => {
20+
step(spinner, 'Generate subgraph')
21+
22+
const scaffold = new Scaffold({
23+
protocol: protocolInstance,
24+
abi,
25+
indexEvents,
26+
contract,
27+
network,
28+
contractName,
29+
subgraphName,
30+
node,
31+
})
32+
33+
return scaffold.generate()
34+
}
35+
36+
const writeScaffoldDirectory = async (scaffold, directory, spinner) => {
37+
// Create directory itself
38+
await fs.mkdirs(directory)
39+
40+
let promises = Object.keys(scaffold).map(async basename => {
41+
let content = scaffold[basename]
42+
let filename = path.join(directory, basename)
43+
44+
// Write file or recurse into subdirectory
45+
if (typeof content === 'string') {
46+
await fs.writeFile(filename, content, { encoding: 'utf-8' })
47+
} else if (content == null) {
48+
return // continue loop
49+
} else {
50+
writeScaffoldDirectory(content, path.join(directory, basename), spinner)
51+
}
52+
})
53+
54+
await Promise.all(promises)
55+
}
56+
57+
const writeScaffold = async (scaffold, directory, spinner) => {
58+
step(spinner, `Write subgraph to directory`)
59+
await writeScaffoldDirectory(scaffold, directory, spinner)
60+
}
61+
62+
module.exports = {
63+
...module.exports,
64+
generateScaffold,
65+
writeScaffold,
66+
}

0 commit comments

Comments
 (0)