@graphprotocol/graph-cli 0.27.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/tendermint.ts +554 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/collections.ts +52 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/numbers.ts +11 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/value.ts +47 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +150 -1
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +2 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +2 -1
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +2 -0
- package/examples/basic-event-handlers/package.json +1 -1
- package/examples/basic-event-handlers/yarn.lock +4 -4
- package/examples/example-subgraph/package.json +1 -1
- package/examples/example-subgraph/yarn.lock +4 -4
- package/package.json +1 -1
- package/src/codegen/schema.js +104 -25
- package/src/codegen/schema.test.js +3 -7
- package/src/command-helpers/network.js +113 -0
- package/src/command-helpers/network.test.js +78 -0
- package/src/commands/build.js +21 -1
- package/src/commands/codegen.js +1 -1
- package/src/commands/deploy.js +1 -1
- package/src/commands/init.js +19 -3
- package/src/protocols/index.js +34 -0
- package/src/protocols/tendermint/manifest.graphql +64 -0
- package/src/protocols/tendermint/subgraph.js +20 -0
- package/src/scaffold/index.js +1 -1
- package/src/subgraph.js +4 -0
- package/src/validation/manifest.js +17 -0
- package/src/validation/schema.js +120 -119
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +2 -0
- package/tests/cli/init/ethereum/from-contract-with-abi.stderr +2 -0
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +2 -0
- package/tests/cli/init/ethereum/from-contract.stderr +2 -0
- package/tests/cli/init/ethereum/from-example.stderr +2 -0
- package/tests/cli/init/near/from-contract.stderr +2 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const yaml = require('yaml')
|
|
3
|
+
const { step, withSpinner } = require('../command-helpers/spinner')
|
|
4
|
+
|
|
5
|
+
const updateSubgraphNetwork = async (toolbox, manifest, network, networksFile, identifierName) =>
|
|
6
|
+
await withSpinner(
|
|
7
|
+
`Update sources network`,
|
|
8
|
+
`Failed to update sources network`,
|
|
9
|
+
`Warnings while updating sources network`,
|
|
10
|
+
async spinner => {
|
|
11
|
+
let allNetworks
|
|
12
|
+
|
|
13
|
+
step(spinner, `Reading networks config`)
|
|
14
|
+
allNetworks = await toolbox.filesystem.read(networksFile, "json")
|
|
15
|
+
let networkConfig = allNetworks[network]
|
|
16
|
+
|
|
17
|
+
// Exit if the network passed with --network does not exits in networks.json
|
|
18
|
+
if(!networkConfig) {
|
|
19
|
+
throw new Error(`Network '${network}' was not found in '${networksFile}'`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
await toolbox.patching.update(manifest, content => {
|
|
23
|
+
let subgraph = yaml.parse(content)
|
|
24
|
+
let networkSources = Object.keys(networkConfig)
|
|
25
|
+
let subgraphSources = subgraph.dataSources.map(value => value.name);
|
|
26
|
+
|
|
27
|
+
// Update the dataSources network config
|
|
28
|
+
subgraph.dataSources = subgraph.dataSources.map(source => {
|
|
29
|
+
if (!networkSources.includes(source.name)) {
|
|
30
|
+
throw new Error(`'${source.name}' was not found in the '${network}' configuration, please update!`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (hasChanges(identifierName, network, networkConfig[source.name], source)) {
|
|
34
|
+
step(spinner, `Update '${source.name}' network configuration`)
|
|
35
|
+
source.network = network
|
|
36
|
+
source.source = source.source.abi ? { abi: source.source.abi } : {}
|
|
37
|
+
Object.assign(source.source, networkConfig[source.name])
|
|
38
|
+
} else {
|
|
39
|
+
step(spinner, `Skip '${source.name}': No changes to network configuration`)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return source
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
// All data sources shoud be on the same network,
|
|
47
|
+
// so we have to update the network of all templates too.
|
|
48
|
+
if(subgraph.templates) {
|
|
49
|
+
subgraph.templates = subgraph.templates.map(template => ({
|
|
50
|
+
...template,
|
|
51
|
+
network,
|
|
52
|
+
}))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let unsusedSources = networkSources.filter(x => !subgraphSources.includes(x))
|
|
56
|
+
|
|
57
|
+
unsusedSources.forEach(source => {
|
|
58
|
+
step(spinner, `dataSource '${source}' from '${networksFile}' not found in ${manifest}`)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
let yaml_doc = new yaml.Document()
|
|
62
|
+
yaml_doc.contents = subgraph
|
|
63
|
+
return yaml_doc.toString()
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const initNetworksConfig = async(toolbox, directory, identifierName) =>
|
|
68
|
+
await withSpinner(
|
|
69
|
+
`Initialize networks config`,
|
|
70
|
+
`Failed to initialize networks config`,
|
|
71
|
+
`Warnings while initializing networks config`,
|
|
72
|
+
async spinner => {
|
|
73
|
+
let subgraphStr = await toolbox.filesystem.read(path.join(directory, 'subgraph.yaml'))
|
|
74
|
+
let subgraph = yaml.parse(subgraphStr)
|
|
75
|
+
|
|
76
|
+
const networks = subgraph.dataSources.reduce((acc, source) =>
|
|
77
|
+
Object.assign(
|
|
78
|
+
acc,
|
|
79
|
+
{
|
|
80
|
+
[source.network]: {
|
|
81
|
+
[source.name]: {
|
|
82
|
+
[identifierName]: source.source.address,
|
|
83
|
+
startBlock: source.source.startBlock,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
, {})
|
|
89
|
+
|
|
90
|
+
await toolbox.filesystem.write(`${directory}/networks.json`, networks)
|
|
91
|
+
|
|
92
|
+
return true
|
|
93
|
+
},
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
// Checks if any network attribute has been changed
|
|
97
|
+
function hasChanges(identifierName, network, networkConfig, dataSource) {
|
|
98
|
+
let networkChanged = dataSource.network !== network
|
|
99
|
+
|
|
100
|
+
// Return directly if the network is different
|
|
101
|
+
if (networkChanged) return networkChanged
|
|
102
|
+
|
|
103
|
+
let addressChanged = networkConfig[identifierName] !== dataSource.source[identifierName]
|
|
104
|
+
|
|
105
|
+
let startBlockChanged = networkConfig.startBlock !== dataSource.source.startBlock
|
|
106
|
+
|
|
107
|
+
return networkChanged || addressChanged || startBlockChanged
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = {
|
|
111
|
+
updateSubgraphNetwork,
|
|
112
|
+
initNetworksConfig
|
|
113
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const { initNetworksConfig, updateSubgraphNetwork } = require('../command-helpers/network')
|
|
2
|
+
const toolbox = require('gluegun/toolbox')
|
|
3
|
+
const yaml = require('yaml')
|
|
4
|
+
|
|
5
|
+
describe('initNetworksConfig', () => {
|
|
6
|
+
beforeAll(async () => {
|
|
7
|
+
await initNetworksConfig(toolbox, './examples/example-subgraph', 'address')
|
|
8
|
+
})
|
|
9
|
+
afterAll(async () => {
|
|
10
|
+
await toolbox.filesystem.remove('./examples/example-subgraph/networks.json')
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('generates networks.json from subgraph.yaml', () => {
|
|
14
|
+
expect(toolbox.filesystem.exists('./examples/example-subgraph/networks.json')).toBe('file')
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('Populates the networks.json file with the data from subgraph.yaml', async () => {
|
|
18
|
+
let networksStr = await toolbox.filesystem.read('./examples/example-subgraph/networks.json')
|
|
19
|
+
let networks = JSON.parse(networksStr)
|
|
20
|
+
|
|
21
|
+
let expected = {
|
|
22
|
+
mainnet: {
|
|
23
|
+
ExampleSubgraph: { address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
expect(networks).toStrictEqual(expected)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('updateSubgraphNetwork', () => {
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
let content = {
|
|
34
|
+
optimism: {
|
|
35
|
+
ExampleSubgraph: { address: '0x12345...' }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await toolbox.filesystem.write('./examples/example-subgraph/networks.json', content)
|
|
40
|
+
await toolbox.filesystem.copy('./examples/example-subgraph/subgraph.yaml', './examples/example-subgraph/subgraph_copy.yaml')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
afterAll(async () => {
|
|
44
|
+
await toolbox.filesystem.remove('./examples/example-subgraph/networks.json')
|
|
45
|
+
await toolbox.filesystem.remove('./examples/example-subgraph/subgraph_copy.yaml')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('Updates subgraph.yaml', async () => {
|
|
49
|
+
let manifest = './examples/example-subgraph/subgraph_copy.yaml'
|
|
50
|
+
let networksFie = './examples/example-subgraph/networks.json'
|
|
51
|
+
let subgraph = await toolbox.filesystem.read(manifest)
|
|
52
|
+
let subgraphObj = yaml.parse(subgraph)
|
|
53
|
+
|
|
54
|
+
let network = subgraphObj.dataSources[0].network
|
|
55
|
+
let address = subgraphObj.dataSources[0].source.address
|
|
56
|
+
|
|
57
|
+
expect(network).toBe('mainnet')
|
|
58
|
+
expect(address).toBe('0x22843e74c59580b3eaf6c233fa67d8b7c561a835')
|
|
59
|
+
|
|
60
|
+
await updateSubgraphNetwork(
|
|
61
|
+
toolbox,
|
|
62
|
+
manifest,
|
|
63
|
+
'optimism',
|
|
64
|
+
networksFie,
|
|
65
|
+
'address'
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
subgraph = await toolbox.filesystem.read(manifest)
|
|
69
|
+
subgraphObj = yaml.parse(subgraph)
|
|
70
|
+
|
|
71
|
+
network = subgraphObj.dataSources[0].network
|
|
72
|
+
address = subgraphObj.dataSources[0].source.address
|
|
73
|
+
|
|
74
|
+
expect(network).toBe('optimism')
|
|
75
|
+
expect(address).toBe('0x12345...')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
})
|
package/src/commands/build.js
CHANGED
|
@@ -2,6 +2,7 @@ const chalk = require('chalk')
|
|
|
2
2
|
|
|
3
3
|
const { createCompiler } = require('../command-helpers/compiler')
|
|
4
4
|
const { fixParameters } = require('../command-helpers/gluegun')
|
|
5
|
+
const { updateSubgraphNetwork } = require('../command-helpers/network')
|
|
5
6
|
const DataSourcesExtractor = require('../command-helpers/data-sources')
|
|
6
7
|
const Protocol = require('../protocols')
|
|
7
8
|
|
|
@@ -16,13 +17,15 @@ Options:
|
|
|
16
17
|
-t, --output-format <format> Output format for mappings (wasm, wast) (default: wasm)
|
|
17
18
|
--skip-migrations Skip subgraph migrations (default: false)
|
|
18
19
|
-w, --watch Regenerate types when subgraph files change (default: false)
|
|
20
|
+
--network <name> Network to use from networks.json
|
|
21
|
+
--network-file <path> Networks file (default: "./networks.json")
|
|
19
22
|
`
|
|
20
23
|
|
|
21
24
|
module.exports = {
|
|
22
25
|
description: 'Builds a subgraph and (optionally) uploads it to IPFS',
|
|
23
26
|
run: async toolbox => {
|
|
24
27
|
// Obtain tools
|
|
25
|
-
let { filesystem, print, system } = toolbox
|
|
28
|
+
let { filesystem, patching, print, system } = toolbox
|
|
26
29
|
|
|
27
30
|
// Parse CLI parameters
|
|
28
31
|
let {
|
|
@@ -37,6 +40,8 @@ module.exports = {
|
|
|
37
40
|
t,
|
|
38
41
|
w,
|
|
39
42
|
watch,
|
|
43
|
+
network,
|
|
44
|
+
networkFile
|
|
40
45
|
} = toolbox.parameters.options
|
|
41
46
|
|
|
42
47
|
// Support both short and long option variants
|
|
@@ -68,6 +73,10 @@ module.exports = {
|
|
|
68
73
|
manifest !== undefined && manifest !== ''
|
|
69
74
|
? manifest
|
|
70
75
|
: filesystem.resolve('subgraph.yaml')
|
|
76
|
+
networkFile =
|
|
77
|
+
networkFile !== undefined && networkFile !== ''
|
|
78
|
+
? networkFile
|
|
79
|
+
: filesystem.resolve("networks.json")
|
|
71
80
|
|
|
72
81
|
// Show help text if requested
|
|
73
82
|
if (help) {
|
|
@@ -86,6 +95,17 @@ module.exports = {
|
|
|
86
95
|
return
|
|
87
96
|
}
|
|
88
97
|
|
|
98
|
+
if (network && filesystem.exists(networkFile) !== "file") {
|
|
99
|
+
print.error(`Network file '${networkFile}' does not exists or is not a file!`)
|
|
100
|
+
process.exitCode = 1
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (network) {
|
|
105
|
+
let identifierName = protocol.getContract().identifierName()
|
|
106
|
+
await updateSubgraphNetwork(toolbox, manifest, network, networkFile, identifierName)
|
|
107
|
+
}
|
|
108
|
+
|
|
89
109
|
let compiler = createCompiler(manifest, {
|
|
90
110
|
ipfs,
|
|
91
111
|
outputDir,
|
package/src/commands/codegen.js
CHANGED
|
@@ -71,7 +71,7 @@ module.exports = {
|
|
|
71
71
|
// because that would mean the CLI would generate code to
|
|
72
72
|
// the wrong AssemblyScript version.
|
|
73
73
|
await assertManifestApiVersion(manifest, '0.0.5')
|
|
74
|
-
await assertGraphTsVersion(path.dirname(manifest), '0.
|
|
74
|
+
await assertGraphTsVersion(path.dirname(manifest), '0.25.0')
|
|
75
75
|
|
|
76
76
|
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
|
|
77
77
|
|
package/src/commands/deploy.js
CHANGED
|
@@ -200,7 +200,7 @@ module.exports = {
|
|
|
200
200
|
// because that would mean the CLI would try to compile code
|
|
201
201
|
// using the wrong AssemblyScript compiler.
|
|
202
202
|
await assertManifestApiVersion(manifest, '0.0.5')
|
|
203
|
-
await assertGraphTsVersion(path.dirname(manifest), '0.
|
|
203
|
+
await assertGraphTsVersion(path.dirname(manifest), '0.25.0')
|
|
204
204
|
|
|
205
205
|
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
|
|
206
206
|
|
package/src/commands/init.js
CHANGED
|
@@ -4,6 +4,7 @@ const immutable = require('immutable')
|
|
|
4
4
|
const os = require('os')
|
|
5
5
|
const path = require('path')
|
|
6
6
|
const toolbox = require('gluegun/toolbox')
|
|
7
|
+
const yaml = require('yaml')
|
|
7
8
|
|
|
8
9
|
const {
|
|
9
10
|
getSubgraphBasename,
|
|
@@ -11,6 +12,7 @@ const {
|
|
|
11
12
|
} = require('../command-helpers/subgraph')
|
|
12
13
|
const DataSourcesExtractor = require('../command-helpers/data-sources')
|
|
13
14
|
const { validateStudioNetwork } = require('../command-helpers/studio')
|
|
15
|
+
const { initNetworksConfig } = require('../command-helpers/network')
|
|
14
16
|
const { withSpinner, step } = require('../command-helpers/spinner')
|
|
15
17
|
const { fixParameters } = require('../command-helpers/gluegun')
|
|
16
18
|
const { chooseNodeUrl } = require('../command-helpers/node')
|
|
@@ -132,7 +134,7 @@ const processInitForm = async (
|
|
|
132
134
|
return `${e.message}
|
|
133
135
|
|
|
134
136
|
Examples:
|
|
135
|
-
|
|
137
|
+
|
|
136
138
|
$ graph init ${os.userInfo().username}/${name}
|
|
137
139
|
$ graph init ${name} --allow-simple-name`
|
|
138
140
|
}
|
|
@@ -285,9 +287,10 @@ const getEtherscanLikeAPIUrl = (network) => {
|
|
|
285
287
|
case "mumbai": return `https://api-testnet.polygonscan.com/api`;
|
|
286
288
|
case "aurora": return `https://api.aurorascan.dev/api`;
|
|
287
289
|
case "aurora-testnet": return `https://api-testnet.aurorascan.dev/api`;
|
|
290
|
+
case "optimism-kovan": return `https://api-kovan-optimistic.etherscan.io/api`;
|
|
288
291
|
default: return `https://api-${network}.etherscan.io/api`;
|
|
289
292
|
}
|
|
290
|
-
}
|
|
293
|
+
}
|
|
291
294
|
|
|
292
295
|
const loadAbiFromEtherscan = async (ABI, network, address) =>
|
|
293
296
|
await withSpinner(
|
|
@@ -355,7 +358,7 @@ module.exports = {
|
|
|
355
358
|
|
|
356
359
|
node = node || g
|
|
357
360
|
;({ node, allowSimpleName } = chooseNodeUrl({ product, studio, node, allowSimpleName }))
|
|
358
|
-
|
|
361
|
+
|
|
359
362
|
if (fromContract && fromExample) {
|
|
360
363
|
print.error(`Only one of --from-example and --from-contract can be used at a time.`)
|
|
361
364
|
process.exitCode = 1
|
|
@@ -685,6 +688,12 @@ const initSubgraphFromExample = async (
|
|
|
685
688
|
return
|
|
686
689
|
}
|
|
687
690
|
|
|
691
|
+
let networkConf = await initNetworksConfig(toolbox, directory, "address")
|
|
692
|
+
if (networkConf !== true) {
|
|
693
|
+
process.exitCode = 1
|
|
694
|
+
return
|
|
695
|
+
}
|
|
696
|
+
|
|
688
697
|
// Update package.json to match the subgraph name
|
|
689
698
|
let prepared = await withSpinner(
|
|
690
699
|
`Update subgraph name and commands in package.json`,
|
|
@@ -826,6 +835,13 @@ const initSubgraphFromContract = async (
|
|
|
826
835
|
return
|
|
827
836
|
}
|
|
828
837
|
|
|
838
|
+
let identifierName = protocolInstance.getContract().identifierName()
|
|
839
|
+
let networkConf = await initNetworksConfig(toolbox, directory, identifierName)
|
|
840
|
+
if (networkConf !== true) {
|
|
841
|
+
process.exitCode = 1
|
|
842
|
+
return
|
|
843
|
+
}
|
|
844
|
+
|
|
829
845
|
// Initialize a fresh Git repository
|
|
830
846
|
let repo = await initRepository(toolbox, directory)
|
|
831
847
|
if (repo !== true) {
|
package/src/protocols/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const EthereumTemplateCodeGen = require('./ethereum/codegen/template')
|
|
|
4
4
|
const EthereumABI = require('./ethereum/abi')
|
|
5
5
|
const EthereumSubgraph = require('./ethereum/subgraph')
|
|
6
6
|
const NearSubgraph = require('./near/subgraph')
|
|
7
|
+
const TendermintSubgraph = require('./tendermint/subgraph')
|
|
7
8
|
const EthereumContract = require('./ethereum/contract')
|
|
8
9
|
const NearContract = require('./near/contract')
|
|
9
10
|
const EthereumManifestScaffold = require('./ethereum/scaffold/manifest')
|
|
@@ -27,6 +28,7 @@ module.exports = class Protocol {
|
|
|
27
28
|
// New networks (or protocol perhaps) shouldn't have the `/contract` anymore (unless a new case makes use of it).
|
|
28
29
|
ethereum: ['ethereum', 'ethereum/contract'],
|
|
29
30
|
near: ['near'],
|
|
31
|
+
tendermint: ['tendermint']
|
|
30
32
|
})
|
|
31
33
|
}
|
|
32
34
|
|
|
@@ -61,6 +63,7 @@ module.exports = class Protocol {
|
|
|
61
63
|
'aurora-testnet',
|
|
62
64
|
],
|
|
63
65
|
near: ['near-mainnet', 'near-testnet'],
|
|
66
|
+
tendermint: ['cosmoshub-4']
|
|
64
67
|
})
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -76,6 +79,8 @@ module.exports = class Protocol {
|
|
|
76
79
|
return 'Ethereum'
|
|
77
80
|
case 'near':
|
|
78
81
|
return 'NEAR'
|
|
82
|
+
case 'tendermint':
|
|
83
|
+
return 'Tendermint'
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
|
|
@@ -93,6 +98,19 @@ module.exports = class Protocol {
|
|
|
93
98
|
return true
|
|
94
99
|
case 'near':
|
|
95
100
|
return false
|
|
101
|
+
case 'tendermint':
|
|
102
|
+
return false
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
hasContract() {
|
|
107
|
+
switch (this.name) {
|
|
108
|
+
case 'ethereum':
|
|
109
|
+
return true
|
|
110
|
+
case 'near':
|
|
111
|
+
return true
|
|
112
|
+
case 'tendermint':
|
|
113
|
+
return false
|
|
96
114
|
}
|
|
97
115
|
}
|
|
98
116
|
|
|
@@ -102,6 +120,8 @@ module.exports = class Protocol {
|
|
|
102
120
|
return true
|
|
103
121
|
case 'near':
|
|
104
122
|
return false
|
|
123
|
+
case 'tendermint':
|
|
124
|
+
return false
|
|
105
125
|
}
|
|
106
126
|
}
|
|
107
127
|
|
|
@@ -111,6 +131,8 @@ module.exports = class Protocol {
|
|
|
111
131
|
return true
|
|
112
132
|
case 'near':
|
|
113
133
|
return false
|
|
134
|
+
case 'tendermint':
|
|
135
|
+
return false
|
|
114
136
|
}
|
|
115
137
|
}
|
|
116
138
|
|
|
@@ -120,6 +142,8 @@ module.exports = class Protocol {
|
|
|
120
142
|
return new EthereumTypeGenerator(options)
|
|
121
143
|
case 'near':
|
|
122
144
|
return null
|
|
145
|
+
case 'tendermint':
|
|
146
|
+
return null
|
|
123
147
|
}
|
|
124
148
|
}
|
|
125
149
|
|
|
@@ -144,6 +168,8 @@ module.exports = class Protocol {
|
|
|
144
168
|
return EthereumABI
|
|
145
169
|
case 'near':
|
|
146
170
|
return null
|
|
171
|
+
case 'tendermint':
|
|
172
|
+
return null
|
|
147
173
|
}
|
|
148
174
|
}
|
|
149
175
|
|
|
@@ -155,6 +181,8 @@ module.exports = class Protocol {
|
|
|
155
181
|
return new EthereumSubgraph(optionsWithProtocol)
|
|
156
182
|
case 'near':
|
|
157
183
|
return new NearSubgraph(optionsWithProtocol)
|
|
184
|
+
case 'tendermint':
|
|
185
|
+
return new TendermintSubgraph(optionsWithProtocol)
|
|
158
186
|
default:
|
|
159
187
|
throw new Error(`Data sources with kind '${this.name}' are not supported yet`)
|
|
160
188
|
}
|
|
@@ -166,6 +194,8 @@ module.exports = class Protocol {
|
|
|
166
194
|
return EthereumContract
|
|
167
195
|
case 'near':
|
|
168
196
|
return NearContract
|
|
197
|
+
case 'tendermint':
|
|
198
|
+
return null
|
|
169
199
|
}
|
|
170
200
|
}
|
|
171
201
|
|
|
@@ -175,6 +205,8 @@ module.exports = class Protocol {
|
|
|
175
205
|
return EthereumManifestScaffold
|
|
176
206
|
case 'near':
|
|
177
207
|
return NearManifestScaffold
|
|
208
|
+
case 'tendermint':
|
|
209
|
+
return null
|
|
178
210
|
}
|
|
179
211
|
}
|
|
180
212
|
|
|
@@ -184,6 +216,8 @@ module.exports = class Protocol {
|
|
|
184
216
|
return EthereumMappingScaffold
|
|
185
217
|
case 'near':
|
|
186
218
|
return NearMappingScaffold
|
|
219
|
+
case 'tendermint':
|
|
220
|
+
return null
|
|
187
221
|
}
|
|
188
222
|
}
|
|
189
223
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Each referenced type's in any of the types below must be listed
|
|
2
|
+
# here either as `scalar` or `type` for the validation code to work
|
|
3
|
+
# properly.
|
|
4
|
+
#
|
|
5
|
+
# That's why `String` is listed as a scalar even though it's built-in
|
|
6
|
+
# GraphQL basic types.
|
|
7
|
+
scalar String
|
|
8
|
+
scalar File
|
|
9
|
+
scalar BigInt
|
|
10
|
+
|
|
11
|
+
type SubgraphManifest {
|
|
12
|
+
specVersion: String!
|
|
13
|
+
schema: Schema!
|
|
14
|
+
description: String
|
|
15
|
+
repository: String
|
|
16
|
+
graft: Graft
|
|
17
|
+
dataSources: [DataSource!]!
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type Schema {
|
|
21
|
+
file: File!
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type DataSource {
|
|
25
|
+
kind: String!
|
|
26
|
+
name: String!
|
|
27
|
+
network: String
|
|
28
|
+
source: ContractSource!
|
|
29
|
+
mapping: ContractMapping!
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type ContractSource {
|
|
33
|
+
startBlock: BigInt
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ContractMapping {
|
|
37
|
+
apiVersion: String!
|
|
38
|
+
language: String!
|
|
39
|
+
file: File!
|
|
40
|
+
entities: [String!]!
|
|
41
|
+
blockHandlers: [BlockHandler!]
|
|
42
|
+
eventHandlers: [EventHandler!]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type BlockHandler {
|
|
46
|
+
handler: String!
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
enum EventOrigin {
|
|
50
|
+
BeginBlock
|
|
51
|
+
DeliverTx
|
|
52
|
+
EndBlock
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type EventHandler {
|
|
56
|
+
event: String!
|
|
57
|
+
origin: EventOrigin
|
|
58
|
+
handler: String!
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type Graft {
|
|
62
|
+
base: String!
|
|
63
|
+
block: BigInt!
|
|
64
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const immutable = require('immutable')
|
|
2
|
+
|
|
3
|
+
module.exports = class TendermintSubgraph {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.manifest = options.manifest
|
|
6
|
+
this.resolveFile = options.resolveFile
|
|
7
|
+
this.protocol = options.protocol
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
validateManifest() {
|
|
11
|
+
return immutable.List()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
handlerTypes() {
|
|
15
|
+
return immutable.List([
|
|
16
|
+
'blockHandlers',
|
|
17
|
+
'eventHandlers',
|
|
18
|
+
])
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/scaffold/index.js
CHANGED
package/src/subgraph.js
CHANGED
|
@@ -158,6 +158,10 @@ At least one such handler must be defined.`,
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
static validateContractValues(manifest, protocol) {
|
|
161
|
+
if (!protocol.hasContract()){
|
|
162
|
+
return immutable.List()
|
|
163
|
+
}
|
|
164
|
+
|
|
161
165
|
return validation.validateContractValues(manifest, protocol)
|
|
162
166
|
}
|
|
163
167
|
|
|
@@ -151,6 +151,23 @@ const validators = immutable.fromJS({
|
|
|
151
151
|
])
|
|
152
152
|
},
|
|
153
153
|
|
|
154
|
+
EnumTypeDefinition: (value, ctx) => {
|
|
155
|
+
const enumValues = ctx.getIn(['type', 'values']).map((v) => {
|
|
156
|
+
return v.getIn(['name', 'value'])
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
const allowedValues = enumValues.toArray().join(', ')
|
|
160
|
+
|
|
161
|
+
return enumValues.includes(value)
|
|
162
|
+
? List()
|
|
163
|
+
: immutable.fromJS([
|
|
164
|
+
{
|
|
165
|
+
path: ctx.get('path'),
|
|
166
|
+
message: `Unexpected enum value: ${value}, allowed values: ${allowedValues}`,
|
|
167
|
+
},
|
|
168
|
+
])
|
|
169
|
+
},
|
|
170
|
+
|
|
154
171
|
String: (value, ctx) =>
|
|
155
172
|
typeof value === 'string'
|
|
156
173
|
? List()
|