@graphprotocol/graph-cli 0.22.2 → 0.23.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/examples/basic-event-handlers/yarn.lock +4 -4
- package/examples/example-subgraph/yarn.lock +4 -4
- package/examples/near/.gitkeep +0 -0
- package/manifest-schema.graphql +35 -2
- package/package.json +1 -1
- package/src/codegen/schema.js +1 -2
- package/src/codegen/template.js +9 -51
- package/src/codegen/typescript.js +7 -0
- package/src/command-helpers/compiler.js +6 -2
- package/src/command-helpers/data-sources.js +38 -0
- package/src/command-helpers/fs.js +8 -0
- package/src/commands/build.js +14 -0
- package/src/commands/codegen.js +8 -0
- package/src/commands/deploy.js +11 -8
- package/src/commands/init.js +5 -8
- package/src/commands/test.js +8 -3
- package/src/compiler/index.js +93 -76
- package/src/{abi.js → protocols/ethereum/abi.js} +0 -0
- package/src/{codegen → protocols/ethereum/codegen}/abi.js +47 -40
- package/src/{codegen → protocols/ethereum/codegen}/abi.test.js +1 -1
- package/src/protocols/ethereum/codegen/template.js +42 -0
- package/src/protocols/ethereum/subgraph.js +205 -0
- package/src/protocols/ethereum/type-generator.js +203 -0
- package/src/protocols/index.js +97 -0
- package/src/protocols/near/subgraph.js +42 -0
- package/src/scaffold.js +3 -2
- package/src/scaffold.test.js +1 -1
- package/src/subgraph.js +30 -252
- package/src/type-generator.js +31 -211
- package/src/validation/index.js +1 -0
- package/src/validation/manifest.js +73 -23
- package/src/validation/schema.js +6 -0
- package/subgraph-ethereum.yaml +134 -0
- package/subgraph-near.yaml +134 -0
- package/tests/cli/init/from-contract/abis/Contract.json +69 -0
- package/tests/cli/init/from-contract/package.json +16 -0
- package/tests/cli/init/from-contract/schema.graphql +6 -0
- package/tests/cli/init/from-contract/src/mapping.ts +49 -0
- package/tests/cli/init/from-contract/subgraph.yaml +26 -0
- package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/near-is-valid/schema.graphql +8 -0
- package/tests/cli/validation/near-is-valid/subgraph.yaml +21 -0
- package/tests/cli/validation.test.js +8 -0
package/src/validation/index.js
CHANGED
|
@@ -51,13 +51,24 @@ const validators = immutable.fromJS({
|
|
|
51
51
|
ScalarTypeDefinition: (value, ctx) =>
|
|
52
52
|
validators.get(ctx.getIn(['type', 'name', 'value']))(value, ctx),
|
|
53
53
|
|
|
54
|
-
UnionTypeDefinition: (value, ctx) =>
|
|
55
|
-
ctx
|
|
54
|
+
UnionTypeDefinition: (value, ctx) => {
|
|
55
|
+
const unionVariants = ctx
|
|
56
56
|
.getIn(['type', 'types'])
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
|
|
58
|
+
let errors = List()
|
|
59
|
+
|
|
60
|
+
for (const variantType of unionVariants) {
|
|
61
|
+
const variantErrors = validateValue(value, ctx.set('type', variantType))
|
|
62
|
+
// No errors found, union variant matched, early return
|
|
63
|
+
if (variantErrors.isEmpty()) {
|
|
64
|
+
return List()
|
|
65
|
+
}
|
|
66
|
+
errors = errors.push(variantErrors)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Return errors from variant that matched the most
|
|
70
|
+
return List(errors.minBy(variantErrors => variantErrors.count()))
|
|
71
|
+
},
|
|
61
72
|
|
|
62
73
|
NamedType: (value, ctx) =>
|
|
63
74
|
validateValue(
|
|
@@ -199,9 +210,8 @@ const validateValue = (value, ctx) => {
|
|
|
199
210
|
}
|
|
200
211
|
}
|
|
201
212
|
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
.filter(dataSource => dataSource.kind === 'ethereum/contract')
|
|
213
|
+
const validateDataSourceForNetwork = (dataSources, protocol) =>
|
|
214
|
+
dataSources.filter(dataSource => protocol.isValidKindName(dataSource.kind))
|
|
205
215
|
.reduce(
|
|
206
216
|
(networks, dataSource) =>
|
|
207
217
|
networks.update(dataSource.network, dataSources =>
|
|
@@ -210,28 +220,37 @@ const validateDataSourceNetworks = value => {
|
|
|
210
220
|
immutable.OrderedMap(),
|
|
211
221
|
)
|
|
212
222
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
223
|
+
const validateDataSourceNetworks = (value, protocol) => {
|
|
224
|
+
const dataSources = [...value.dataSources, ...(value.templates || [])]
|
|
225
|
+
|
|
226
|
+
// Networks found valid for a protocol.
|
|
227
|
+
// By searching through all data sources and templates.
|
|
228
|
+
const networks = validateDataSourceForNetwork(dataSources, protocol)
|
|
229
|
+
|
|
230
|
+
if (networks.size > 1) {
|
|
231
|
+
return immutable.fromJS([
|
|
232
|
+
{
|
|
233
|
+
path: [],
|
|
234
|
+
message: `Conflicting networks used in data sources and templates:
|
|
218
235
|
${networks
|
|
219
236
|
.map(
|
|
220
237
|
(dataSources, network) =>
|
|
221
|
-
|
|
238
|
+
` ${
|
|
222
239
|
network === undefined
|
|
223
240
|
? 'Data sources and templates having no network set'
|
|
224
|
-
|
|
225
|
-
|
|
241
|
+
: `Data sources and templates using '${network}'`
|
|
242
|
+
}:\n${dataSources.map(ds => ` - ${ds}`).join('\n')}`,
|
|
226
243
|
)
|
|
227
244
|
.join('\n')}
|
|
228
245
|
Recommendation: Make all data sources and templates use the same network name.`,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
246
|
+
},
|
|
247
|
+
])
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return List()
|
|
232
251
|
}
|
|
233
252
|
|
|
234
|
-
const validateManifest = (value, type, schema, { resolveFile }) => {
|
|
253
|
+
const validateManifest = (value, type, schema, protocol, { resolveFile }) => {
|
|
235
254
|
// Validate manifest using the GraphQL schema that defines its structure
|
|
236
255
|
let errors =
|
|
237
256
|
value !== null && value !== undefined
|
|
@@ -260,7 +279,38 @@ const validateManifest = (value, type, schema, { resolveFile }) => {
|
|
|
260
279
|
|
|
261
280
|
// Validate that all data sources are for the same `network` (this includes
|
|
262
281
|
// _no_ network at all)
|
|
263
|
-
return validateDataSourceNetworks(value)
|
|
282
|
+
return validateDataSourceNetworks(value, protocol)
|
|
264
283
|
}
|
|
265
284
|
|
|
266
|
-
|
|
285
|
+
const validateContractValues = (manifest, protocol, fieldName, validator, errorMessage) =>
|
|
286
|
+
manifest
|
|
287
|
+
.get('dataSources')
|
|
288
|
+
.filter(dataSource => protocol.isValidKindName(dataSource.get('kind')))
|
|
289
|
+
.reduce((errors, dataSource, dataSourceIndex) => {
|
|
290
|
+
let path = ['dataSources', dataSourceIndex, 'source', fieldName]
|
|
291
|
+
|
|
292
|
+
// No need to validate if the source has no contract field
|
|
293
|
+
if (!dataSource.get('source').has(fieldName)) {
|
|
294
|
+
return errors
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
let contractValue = dataSource.getIn(['source', fieldName])
|
|
298
|
+
|
|
299
|
+
// Validate whether the contract is valid
|
|
300
|
+
if (validator(contractValue)) {
|
|
301
|
+
return errors
|
|
302
|
+
} else {
|
|
303
|
+
return errors.push(
|
|
304
|
+
immutable.fromJS({
|
|
305
|
+
path,
|
|
306
|
+
message: `\
|
|
307
|
+
Contract ${fieldName} is invalid: ${contractValue}${errorMessage ? `\n${errorMessage}` : ''}`,
|
|
308
|
+
}),
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
}, immutable.List())
|
|
312
|
+
|
|
313
|
+
module.exports = {
|
|
314
|
+
validateManifest,
|
|
315
|
+
validateContractValues,
|
|
316
|
+
}
|
package/src/validation/schema.js
CHANGED
|
@@ -20,6 +20,12 @@ const BUILTIN_SCALAR_TYPES = [
|
|
|
20
20
|
const TYPE_SUGGESTIONS = [
|
|
21
21
|
['Address', 'Bytes'],
|
|
22
22
|
['address', 'Bytes'],
|
|
23
|
+
['Account', 'String'],
|
|
24
|
+
['account', 'String'],
|
|
25
|
+
['AccountId', 'String'],
|
|
26
|
+
['AccountID', 'String'],
|
|
27
|
+
['accountId', 'String'],
|
|
28
|
+
['accountid', 'String'],
|
|
23
29
|
['bytes', 'Bytes'],
|
|
24
30
|
['string', 'String'],
|
|
25
31
|
['bool', 'Boolean'],
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
specVersion: 0.0.2
|
|
2
|
+
schema:
|
|
3
|
+
file: ./schema.graphql
|
|
4
|
+
dataSources:
|
|
5
|
+
- kind: ethereum/contract
|
|
6
|
+
name: NiftyInk
|
|
7
|
+
network: xdai
|
|
8
|
+
source:
|
|
9
|
+
address: "0x49dE55fbA08af88f55EB797a456fdf76B151c8b0"
|
|
10
|
+
abi: NiftyInk
|
|
11
|
+
startBlock: 11296636
|
|
12
|
+
mapping:
|
|
13
|
+
kind: ethereum/events
|
|
14
|
+
apiVersion: 0.0.5
|
|
15
|
+
language: wasm/assemblyscript
|
|
16
|
+
entities:
|
|
17
|
+
- Ink
|
|
18
|
+
- Artist
|
|
19
|
+
- InkNumberLookUp
|
|
20
|
+
abis:
|
|
21
|
+
- name: NiftyInk
|
|
22
|
+
file: ./abis/NiftyInk.json
|
|
23
|
+
eventHandlers:
|
|
24
|
+
- event: newInk(uint256,indexed address,string,string,uint256)
|
|
25
|
+
handler: handlenewInk
|
|
26
|
+
callHandlers:
|
|
27
|
+
- function: setPrice(string,uint256)
|
|
28
|
+
handler: handleSetPrice
|
|
29
|
+
- function: setPriceFromSignature(string,uint256,bytes)
|
|
30
|
+
handler: handleSetPriceFromSignature
|
|
31
|
+
file: ./src/mapping.ts
|
|
32
|
+
- kind: ethereum/contract
|
|
33
|
+
name: NiftyToken
|
|
34
|
+
network: xdai
|
|
35
|
+
source:
|
|
36
|
+
address: "0xCF964c89f509a8c0Ac36391c5460dF94B91daba5"
|
|
37
|
+
abi: NiftyToken
|
|
38
|
+
startBlock: 11296637
|
|
39
|
+
mapping:
|
|
40
|
+
kind: ethereum/events
|
|
41
|
+
apiVersion: 0.0.5
|
|
42
|
+
language: wasm/assemblyscript
|
|
43
|
+
entities:
|
|
44
|
+
- Ink
|
|
45
|
+
- Token
|
|
46
|
+
- Sale
|
|
47
|
+
- Transfer
|
|
48
|
+
abis:
|
|
49
|
+
- name: NiftyToken
|
|
50
|
+
file: ./abis/NiftyToken.json
|
|
51
|
+
- name: NiftyInk
|
|
52
|
+
file: ./abis/NiftyInk.json
|
|
53
|
+
eventHandlers:
|
|
54
|
+
- event: Transfer(indexed address,indexed address,indexed uint256)
|
|
55
|
+
handler: handleTransfer
|
|
56
|
+
- event: boughtInk(uint256,string,address,uint256)
|
|
57
|
+
handler: handleBoughtInk
|
|
58
|
+
- event: mintedInk(uint256,string,address)
|
|
59
|
+
handler: handleMintedInk
|
|
60
|
+
callHandlers:
|
|
61
|
+
- function: setTokenPrice(uint256,uint256)
|
|
62
|
+
handler: handleSetTokenPrice
|
|
63
|
+
file: ./src/mapping.ts
|
|
64
|
+
# - kind: ethereum/contract
|
|
65
|
+
# name: NiftyMain
|
|
66
|
+
# network: mainnet
|
|
67
|
+
# source:
|
|
68
|
+
# address: "0xc02697c417DdAcfbe5EdbF23eDad956BC883F4fb"
|
|
69
|
+
# abi: NiftyMain
|
|
70
|
+
# startBlock: 10609660
|
|
71
|
+
# mapping:
|
|
72
|
+
# kind: ethereum/events
|
|
73
|
+
# apiVersion: 0.0.4
|
|
74
|
+
# language: wasm/assemblyscript
|
|
75
|
+
# entities:
|
|
76
|
+
# - Token
|
|
77
|
+
# - Transfer
|
|
78
|
+
# abis:
|
|
79
|
+
# - name: NiftyMain
|
|
80
|
+
# file: ./abis/NiftyMain.json
|
|
81
|
+
# - name: NiftyToken
|
|
82
|
+
# file: ./abis/NiftyToken.json
|
|
83
|
+
# eventHandlers:
|
|
84
|
+
# - event: Transfer(indexed address,indexed address,indexed uint256)
|
|
85
|
+
# handler: handleTransfer
|
|
86
|
+
# - event: mintedInk(uint256,string,address)
|
|
87
|
+
# handler: handleMintedOnMain
|
|
88
|
+
# file: ./src/mapping.ts
|
|
89
|
+
- kind: ethereum/contract
|
|
90
|
+
name: NiftyMediator
|
|
91
|
+
network: xdai
|
|
92
|
+
source:
|
|
93
|
+
address: "0x73cA9C4e72fF109259cf7374F038faf950949C51"
|
|
94
|
+
abi: NiftyMediator
|
|
95
|
+
startBlock: 11296637
|
|
96
|
+
mapping:
|
|
97
|
+
kind: ethereum/events
|
|
98
|
+
apiVersion: 0.0.5
|
|
99
|
+
language: wasm/assemblyscript
|
|
100
|
+
entities:
|
|
101
|
+
- Token
|
|
102
|
+
abis:
|
|
103
|
+
- name: NiftyMediator
|
|
104
|
+
file: ./abis/NiftyMediator.json
|
|
105
|
+
- name: NiftyToken
|
|
106
|
+
file: ./abis/NiftyToken.json
|
|
107
|
+
eventHandlers:
|
|
108
|
+
- event: tokenSentViaBridge(uint256,bytes32)
|
|
109
|
+
handler: handleTokenSentViaBridge
|
|
110
|
+
- event: newPrice(uint256)
|
|
111
|
+
handler: handleNewRelayPrice
|
|
112
|
+
file: ./src/mapping.ts
|
|
113
|
+
- kind: ethereum/contract
|
|
114
|
+
name: Liker
|
|
115
|
+
network: xdai
|
|
116
|
+
source:
|
|
117
|
+
address: "0xBD0621dcb64e1EEd503f709422b019B2fA197aF6"
|
|
118
|
+
abi: Liker
|
|
119
|
+
startBlock: 11296637
|
|
120
|
+
mapping:
|
|
121
|
+
kind: ethereum/events
|
|
122
|
+
apiVersion: 0.0.5
|
|
123
|
+
language: wasm/assemblyscript
|
|
124
|
+
entities:
|
|
125
|
+
- InkLookUp
|
|
126
|
+
- Like
|
|
127
|
+
- Ink
|
|
128
|
+
abis:
|
|
129
|
+
- name: Liker
|
|
130
|
+
file: ./abis/Liker.json
|
|
131
|
+
eventHandlers:
|
|
132
|
+
- event: liked(uint256,address,uint256,uint256,address)
|
|
133
|
+
handler: handleLikedInk
|
|
134
|
+
file: ./src/mapping.ts
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
specVersion: 0.0.2
|
|
2
|
+
schema:
|
|
3
|
+
file: ./schema.graphql
|
|
4
|
+
dataSources:
|
|
5
|
+
- kind: ethereum/contract
|
|
6
|
+
name: NiftyInk
|
|
7
|
+
network: xdai
|
|
8
|
+
source:
|
|
9
|
+
address: "0x49dE55fbA08af88f55EB797a456fdf76B151c8b0"
|
|
10
|
+
abi: NiftyInk
|
|
11
|
+
startBlock: 11296636
|
|
12
|
+
mapping:
|
|
13
|
+
kind: ethereum/events
|
|
14
|
+
apiVersion: 0.0.5
|
|
15
|
+
language: wasm/assemblyscript
|
|
16
|
+
entities:
|
|
17
|
+
- Ink
|
|
18
|
+
- Artist
|
|
19
|
+
- InkNumberLookUp
|
|
20
|
+
abis:
|
|
21
|
+
- name: NiftyInk
|
|
22
|
+
file: ./abis/NiftyInk.json
|
|
23
|
+
eventHandlers:
|
|
24
|
+
- event: newInk(uint256,indexed address,string,string,uint256)
|
|
25
|
+
handler: handlenewInk
|
|
26
|
+
callHandlers:
|
|
27
|
+
- function: setPrice(string,uint256)
|
|
28
|
+
handler: handleSetPrice
|
|
29
|
+
- function: setPriceFromSignature(string,uint256,bytes)
|
|
30
|
+
handler: handleSetPriceFromSignature
|
|
31
|
+
file: ./src/mapping.ts
|
|
32
|
+
- kind: ethereum/contract
|
|
33
|
+
name: NiftyToken
|
|
34
|
+
network: xdai
|
|
35
|
+
source:
|
|
36
|
+
address: "0xCF964c89f509a8c0Ac36391c5460dF94B91daba5"
|
|
37
|
+
abi: NiftyToken
|
|
38
|
+
startBlock: 11296637
|
|
39
|
+
mapping:
|
|
40
|
+
kind: ethereum/events
|
|
41
|
+
apiVersion: 0.0.5
|
|
42
|
+
language: wasm/assemblyscript
|
|
43
|
+
entities:
|
|
44
|
+
- Ink
|
|
45
|
+
- Token
|
|
46
|
+
- Sale
|
|
47
|
+
- Transfer
|
|
48
|
+
abis:
|
|
49
|
+
- name: NiftyToken
|
|
50
|
+
file: ./abis/NiftyToken.json
|
|
51
|
+
- name: NiftyInk
|
|
52
|
+
file: ./abis/NiftyInk.json
|
|
53
|
+
eventHandlers:
|
|
54
|
+
- event: Transfer(indexed address,indexed address,indexed uint256)
|
|
55
|
+
handler: handleTransfer
|
|
56
|
+
- event: boughtInk(uint256,string,address,uint256)
|
|
57
|
+
handler: handleBoughtInk
|
|
58
|
+
- event: mintedInk(uint256,string,address)
|
|
59
|
+
handler: handleMintedInk
|
|
60
|
+
callHandlers:
|
|
61
|
+
- function: setTokenPrice(uint256,uint256)
|
|
62
|
+
handler: handleSetTokenPrice
|
|
63
|
+
file: ./src/mapping.ts
|
|
64
|
+
# - kind: ethereum/contract
|
|
65
|
+
# name: NiftyMain
|
|
66
|
+
# network: mainnet
|
|
67
|
+
# source:
|
|
68
|
+
# address: "0xc02697c417DdAcfbe5EdbF23eDad956BC883F4fb"
|
|
69
|
+
# abi: NiftyMain
|
|
70
|
+
# startBlock: 10609660
|
|
71
|
+
# mapping:
|
|
72
|
+
# kind: ethereum/events
|
|
73
|
+
# apiVersion: 0.0.4
|
|
74
|
+
# language: wasm/assemblyscript
|
|
75
|
+
# entities:
|
|
76
|
+
# - Token
|
|
77
|
+
# - Transfer
|
|
78
|
+
# abis:
|
|
79
|
+
# - name: NiftyMain
|
|
80
|
+
# file: ./abis/NiftyMain.json
|
|
81
|
+
# - name: NiftyToken
|
|
82
|
+
# file: ./abis/NiftyToken.json
|
|
83
|
+
# eventHandlers:
|
|
84
|
+
# - event: Transfer(indexed address,indexed address,indexed uint256)
|
|
85
|
+
# handler: handleTransfer
|
|
86
|
+
# - event: mintedInk(uint256,string,address)
|
|
87
|
+
# handler: handleMintedOnMain
|
|
88
|
+
# file: ./src/mapping.ts
|
|
89
|
+
- kind: ethereum/contract
|
|
90
|
+
name: NiftyMediator
|
|
91
|
+
network: xdai
|
|
92
|
+
source:
|
|
93
|
+
address: "0x73cA9C4e72fF109259cf7374F038faf950949C51"
|
|
94
|
+
abi: NiftyMediator
|
|
95
|
+
startBlock: 11296637
|
|
96
|
+
mapping:
|
|
97
|
+
kind: ethereum/events
|
|
98
|
+
apiVersion: 0.0.5
|
|
99
|
+
language: wasm/assemblyscript
|
|
100
|
+
entities:
|
|
101
|
+
- Token
|
|
102
|
+
abis:
|
|
103
|
+
- name: NiftyMediator
|
|
104
|
+
file: ./abis/NiftyMediator.json
|
|
105
|
+
- name: NiftyToken
|
|
106
|
+
file: ./abis/NiftyToken.json
|
|
107
|
+
eventHandlers:
|
|
108
|
+
- event: tokenSentViaBridge(uint256,bytes32)
|
|
109
|
+
handler: handleTokenSentViaBridge
|
|
110
|
+
- event: newPrice(uint256)
|
|
111
|
+
handler: handleNewRelayPrice
|
|
112
|
+
file: ./src/mapping.ts
|
|
113
|
+
- kind: ethereum/contract
|
|
114
|
+
name: Liker
|
|
115
|
+
network: xdai
|
|
116
|
+
source:
|
|
117
|
+
address: "0xBD0621dcb64e1EEd503f709422b019B2fA197aF6"
|
|
118
|
+
abi: Liker
|
|
119
|
+
startBlock: 11296637
|
|
120
|
+
mapping:
|
|
121
|
+
kind: ethereum/events
|
|
122
|
+
apiVersion: 0.0.5
|
|
123
|
+
language: wasm/assemblyscript
|
|
124
|
+
entities:
|
|
125
|
+
- InkLookUp
|
|
126
|
+
- Like
|
|
127
|
+
- Ink
|
|
128
|
+
abis:
|
|
129
|
+
- name: Liker
|
|
130
|
+
file: ./abis/Liker.json
|
|
131
|
+
eventHandlers:
|
|
132
|
+
- event: liked(uint256,address,uint256,uint256,address)
|
|
133
|
+
handler: handleLikedInk
|
|
134
|
+
file: ./src/mapping.ts
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"constant": true,
|
|
4
|
+
"inputs": [],
|
|
5
|
+
"name": "proxyOwner",
|
|
6
|
+
"outputs": [{ "name": "", "type": "address" }],
|
|
7
|
+
"payable": false,
|
|
8
|
+
"stateMutability": "view",
|
|
9
|
+
"type": "function"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"constant": true,
|
|
13
|
+
"inputs": [],
|
|
14
|
+
"name": "currentContract",
|
|
15
|
+
"outputs": [{ "name": "", "type": "address" }],
|
|
16
|
+
"payable": false,
|
|
17
|
+
"stateMutability": "view",
|
|
18
|
+
"type": "function"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"constant": true,
|
|
22
|
+
"inputs": [],
|
|
23
|
+
"name": "owner",
|
|
24
|
+
"outputs": [{ "name": "", "type": "address" }],
|
|
25
|
+
"payable": false,
|
|
26
|
+
"stateMutability": "view",
|
|
27
|
+
"type": "function"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"constant": false,
|
|
31
|
+
"inputs": [
|
|
32
|
+
{ "name": "newContract", "type": "address" },
|
|
33
|
+
{ "name": "data", "type": "bytes" }
|
|
34
|
+
],
|
|
35
|
+
"name": "upgrade",
|
|
36
|
+
"outputs": [],
|
|
37
|
+
"payable": false,
|
|
38
|
+
"stateMutability": "nonpayable",
|
|
39
|
+
"type": "function"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"constant": false,
|
|
43
|
+
"inputs": [{ "name": "_newOwner", "type": "address" }],
|
|
44
|
+
"name": "transferOwnership",
|
|
45
|
+
"outputs": [],
|
|
46
|
+
"payable": false,
|
|
47
|
+
"stateMutability": "nonpayable",
|
|
48
|
+
"type": "function"
|
|
49
|
+
},
|
|
50
|
+
{ "payable": true, "stateMutability": "payable", "type": "fallback" },
|
|
51
|
+
{
|
|
52
|
+
"anonymous": false,
|
|
53
|
+
"inputs": [
|
|
54
|
+
{ "indexed": true, "name": "newContract", "type": "address" },
|
|
55
|
+
{ "indexed": false, "name": "initializedWith", "type": "bytes" }
|
|
56
|
+
],
|
|
57
|
+
"name": "Upgrade",
|
|
58
|
+
"type": "event"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"anonymous": false,
|
|
62
|
+
"inputs": [
|
|
63
|
+
{ "indexed": false, "name": "_prevOwner", "type": "address" },
|
|
64
|
+
{ "indexed": false, "name": "_newOwner", "type": "address" }
|
|
65
|
+
],
|
|
66
|
+
"name": "OwnerUpdate",
|
|
67
|
+
"type": "event"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "subgraph-from-contract",
|
|
3
|
+
"license": "UNLICENSED",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"codegen": "graph codegen",
|
|
6
|
+
"build": "graph build",
|
|
7
|
+
"deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ user/subgraph-from-contract",
|
|
8
|
+
"create-local": "graph create --node http://localhost:8020/ user/subgraph-from-contract",
|
|
9
|
+
"remove-local": "graph remove --node http://localhost:8020/ user/subgraph-from-contract",
|
|
10
|
+
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 user/subgraph-from-contract"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@graphprotocol/graph-cli": "file:../../../../",
|
|
14
|
+
"@graphprotocol/graph-ts": "0.22.1"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BigInt } from "@graphprotocol/graph-ts"
|
|
2
|
+
import { Contract, Upgrade, OwnerUpdate } from "../generated/Contract/Contract"
|
|
3
|
+
import { ExampleEntity } from "../generated/schema"
|
|
4
|
+
|
|
5
|
+
export function handleUpgrade(event: Upgrade): void {
|
|
6
|
+
// Entities can be loaded from the store using a string ID; this ID
|
|
7
|
+
// needs to be unique across all entities of the same type
|
|
8
|
+
let entity = ExampleEntity.load(event.transaction.from.toHex())
|
|
9
|
+
|
|
10
|
+
// Entities only exist after they have been saved to the store;
|
|
11
|
+
// `null` checks allow to create entities on demand
|
|
12
|
+
if (!entity) {
|
|
13
|
+
entity = new ExampleEntity(event.transaction.from.toHex())
|
|
14
|
+
|
|
15
|
+
// Entity fields can be set using simple assignments
|
|
16
|
+
entity.count = BigInt.fromI32(0)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// BigInt and BigDecimal math are supported
|
|
20
|
+
entity.count = entity.count + BigInt.fromI32(1)
|
|
21
|
+
|
|
22
|
+
// Entity fields can be set based on event parameters
|
|
23
|
+
entity.newContract = event.params.newContract
|
|
24
|
+
entity.initializedWith = event.params.initializedWith
|
|
25
|
+
|
|
26
|
+
// Entities can be written to the store with `.save()`
|
|
27
|
+
entity.save()
|
|
28
|
+
|
|
29
|
+
// Note: If a handler doesn't require existing field values, it is faster
|
|
30
|
+
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
31
|
+
// `new Entity(...)`, set the fields that should be updated and save the
|
|
32
|
+
// entity back to the store. Fields that were not set or unset remain
|
|
33
|
+
// unchanged, allowing for partial updates to be applied.
|
|
34
|
+
|
|
35
|
+
// It is also possible to access smart contracts from mappings. For
|
|
36
|
+
// example, the contract that has emitted the event can be connected to
|
|
37
|
+
// with:
|
|
38
|
+
//
|
|
39
|
+
// let contract = Contract.bind(event.address)
|
|
40
|
+
//
|
|
41
|
+
// The following functions can then be called on this contract to access
|
|
42
|
+
// state variables and other data:
|
|
43
|
+
//
|
|
44
|
+
// - contract.proxyOwner(...)
|
|
45
|
+
// - contract.currentContract(...)
|
|
46
|
+
// - contract.owner(...)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function handleOwnerUpdate(event: OwnerUpdate): void {}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
specVersion: 0.0.1
|
|
2
|
+
schema:
|
|
3
|
+
file: ./schema.graphql
|
|
4
|
+
dataSources:
|
|
5
|
+
- kind: ethereum/contract
|
|
6
|
+
name: Contract
|
|
7
|
+
network: mainnet
|
|
8
|
+
source:
|
|
9
|
+
address: "0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d"
|
|
10
|
+
abi: Contract
|
|
11
|
+
mapping:
|
|
12
|
+
kind: ethereum/events
|
|
13
|
+
apiVersion: 0.0.5
|
|
14
|
+
language: wasm/assemblyscript
|
|
15
|
+
entities:
|
|
16
|
+
- Upgrade
|
|
17
|
+
- OwnerUpdate
|
|
18
|
+
abis:
|
|
19
|
+
- name: Contract
|
|
20
|
+
file: ./abis/Contract.json
|
|
21
|
+
eventHandlers:
|
|
22
|
+
- event: Upgrade(indexed address,bytes)
|
|
23
|
+
handler: handleUpgrade
|
|
24
|
+
- event: OwnerUpdate(address,address)
|
|
25
|
+
handler: handleOwnerUpdate
|
|
26
|
+
file: ./src/mapping.ts
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
specVersion: 0.0.1
|
|
2
|
+
repository: https://github.com/graphprotocol/near-subgraph
|
|
3
|
+
description: NEAR subgraph
|
|
4
|
+
schema:
|
|
5
|
+
file: ./schema.graphql
|
|
6
|
+
dataSources:
|
|
7
|
+
- kind: near
|
|
8
|
+
name: NearSubgraph
|
|
9
|
+
source:
|
|
10
|
+
account: wnear.flux-dev
|
|
11
|
+
startBlock: 1
|
|
12
|
+
mapping:
|
|
13
|
+
apiVersion: 0.0.5
|
|
14
|
+
language: wasm/assemblyscript
|
|
15
|
+
file: ./mapping.ts
|
|
16
|
+
entities:
|
|
17
|
+
- ExampleEntity
|
|
18
|
+
blockHandlers:
|
|
19
|
+
- handler: handleNewBlock
|
|
20
|
+
receiptHandlers:
|
|
21
|
+
- handler: handleReceipt
|
|
@@ -144,6 +144,14 @@ describe('Validation', () => {
|
|
|
144
144
|
exitCode: 1,
|
|
145
145
|
},
|
|
146
146
|
)
|
|
147
|
+
cliTest(
|
|
148
|
+
'NEAR is a valid chain',
|
|
149
|
+
['codegen', '--skip-migrations'],
|
|
150
|
+
'validation/near-is-valid',
|
|
151
|
+
{
|
|
152
|
+
exitCode: 0,
|
|
153
|
+
},
|
|
154
|
+
)
|
|
147
155
|
cliTest(
|
|
148
156
|
'Deprecated template format gives nice error',
|
|
149
157
|
['codegen', '--skip-migrations'],
|