@graphprotocol/graph-cli 0.29.0 → 0.30.0-alpha.1

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.
Files changed (56) hide show
  1. package/examples/basic-event-handlers/node_modules/keccak/build/Makefile +1 -1
  2. package/examples/basic-event-handlers/node_modules/keccak/build/Release/.deps/Release/obj.target/keccak/src/addon.o.d.raw +16 -16
  3. package/examples/basic-event-handlers/node_modules/keccak/build/config.gypi +4 -4
  4. package/examples/basic-event-handlers/node_modules/keccak/build/keccak.target.mk +14 -14
  5. package/examples/basic-event-handlers/node_modules/websocket/build/Makefile +1 -1
  6. package/examples/basic-event-handlers/node_modules/websocket/build/Release/.deps/Release/obj.target/bufferutil/src/bufferutil.o.d.raw +16 -16
  7. package/examples/basic-event-handlers/node_modules/websocket/build/bufferutil.target.mk +14 -14
  8. package/examples/basic-event-handlers/node_modules/websocket/build/config.gypi +1 -1
  9. package/examples/basic-event-handlers/node_modules/websocket/build/validation.target.mk +14 -14
  10. package/examples/basic-event-handlers/package.json +1 -1
  11. package/examples/basic-event-handlers/yarn.lock +4 -4
  12. package/examples/example-subgraph/package.json +1 -1
  13. package/examples/example-subgraph/yarn.lock +4 -4
  14. package/package.json +1 -1
  15. package/resources/test/docker-compose.yml +4 -2
  16. package/src/codegen/schema.js +3 -44
  17. package/src/codegen/schema.test.js +0 -6
  18. package/src/codegen/types/conversions.js +19 -19
  19. package/src/codegen/types/index.js +0 -25
  20. package/src/codegen/types/index.test.js +0 -22
  21. package/src/commands/deploy.js +0 -5
  22. package/src/commands/init.js +1 -0
  23. package/src/migrations/mapping_api_version_0_0_5.js +1 -1
  24. package/src/migrations/mapping_api_version_0_0_6.js +74 -0
  25. package/src/migrations/spec_version_0_0_2.js +1 -1
  26. package/src/migrations/spec_version_0_0_3.js +29 -0
  27. package/src/migrations/spec_version_0_0_4.js +25 -0
  28. package/src/migrations.js +4 -0
  29. package/src/protocols/ethereum/manifest.graphql +2 -0
  30. package/src/protocols/index.js +2 -2
  31. package/src/scaffold/index.js +1 -1
  32. package/src/validation/manifest.js +64 -12
  33. package/tests/cli/init/ethereum/from-example/.gitattributes +1 -0
  34. package/tests/cli/init/ethereum/from-example/LICENSE +21 -0
  35. package/tests/cli/init/ethereum/from-example/README.md +3 -0
  36. package/tests/cli/init/ethereum/from-example/abis/Gravity.json +1 -0
  37. package/tests/cli/init/ethereum/from-example/bin/Counter.bin +1 -0
  38. package/tests/cli/init/ethereum/from-example/contracts/Gravity.sol +63 -0
  39. package/tests/cli/init/ethereum/from-example/contracts/Migrations.sol +23 -0
  40. package/tests/cli/init/ethereum/from-example/docker-compose.yml +39 -0
  41. package/tests/cli/init/ethereum/from-example/migrations/1_initial_migration.js +5 -0
  42. package/tests/cli/init/ethereum/from-example/migrations/2_deploy_contract.js +5 -0
  43. package/tests/cli/init/ethereum/from-example/migrations/3_create_gravatars.js +15 -0
  44. package/tests/cli/init/ethereum/from-example/networks.json +7 -0
  45. package/tests/cli/init/ethereum/from-example/package.json +23 -0
  46. package/tests/cli/init/ethereum/from-example/schema.graphql +6 -0
  47. package/tests/cli/init/ethereum/from-example/src/mapping.ts +22 -0
  48. package/tests/cli/init/ethereum/from-example/subgraph.yaml +27 -0
  49. package/tests/cli/init/ethereum/from-example/truffle.js +27 -0
  50. package/tests/cli/init/ethereum/from-example/yarn.lock +5977 -0
  51. package/tests/cli/validation/conflicting-protocol-names/Abi.json +7 -0
  52. package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
  53. package/tests/cli/validation/conflicting-protocol-names/schema.graphql +3 -0
  54. package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +41 -0
  55. package/tests/cli/validation/conflicting-protocol-names.stderr +10 -0
  56. package/tests/cli/validation.test.js +9 -0
@@ -21,7 +21,7 @@ module.exports = {
21
21
 
22
22
  let manifest = loadManifest(manifestFile)
23
23
  return (
24
- // Only migrate if the graph-ts version is >= 0.23.0...
24
+ // Only migrate if the graph-ts version is >= 0.24.0...
25
25
  // Coerce needed because we may be dealing with an alpha version
26
26
  // and in the `semver` library this would not return true on equality.
27
27
  semver.gte(semver.coerce(graphTsVersion), '0.24.0') &&
@@ -0,0 +1,74 @@
1
+ const fs = require('fs-extra')
2
+ const semver = require('semver')
3
+ const toolbox = require('gluegun/toolbox')
4
+ const yaml = require('js-yaml')
5
+ const { loadManifest } = require('./util/load-manifest')
6
+ const { getGraphTsVersion } = require('./util/versions')
7
+
8
+ // If any of the manifest apiVersions are 0.0.6, replace them with 0.0.7
9
+ module.exports = {
10
+ name: 'Bump mapping apiVersion from 0.0.6 to 0.0.7',
11
+ predicate: async ({ sourceDir, manifestFile }) => {
12
+ // Obtain the graph-ts version, if possible
13
+ let graphTsVersion
14
+ try {
15
+ graphTsVersion = await getGraphTsVersion(sourceDir)
16
+ } catch (_) {
17
+ // If we cannot obtain the version, return a hint that the graph-ts
18
+ // hasn't been installed yet
19
+ return 'graph-ts dependency not installed yet'
20
+ }
21
+
22
+ let manifest = loadManifest(manifestFile)
23
+ return (
24
+ // Only migrate if the graph-ts version is >= 0.27.0...
25
+ // Coerce needed because we may be dealing with an alpha version
26
+ // and in the `semver` library this would not return true on equality.
27
+ semver.gte(semver.coerce(graphTsVersion), '0.27.0') &&
28
+ // ...and we have a manifest with mapping > apiVersion = 0.0.6
29
+ manifest &&
30
+ typeof manifest === 'object' &&
31
+ Array.isArray(manifest.dataSources) &&
32
+ (manifest.dataSources.reduce(
33
+ (hasOldMappings, dataSource) =>
34
+ hasOldMappings ||
35
+ (typeof dataSource === 'object' &&
36
+ dataSource.mapping &&
37
+ typeof dataSource.mapping === 'object' &&
38
+ dataSource.mapping.apiVersion === '0.0.6'),
39
+ false,
40
+ ) ||
41
+ (Array.isArray(manifest.templates) &&
42
+ manifest.templates.reduce(
43
+ (hasOldMappings, template) =>
44
+ hasOldMappings ||
45
+ (typeof template === 'object' &&
46
+ template.mapping &&
47
+ typeof template.mapping === 'object' &&
48
+ template.mapping.apiVersion === '0.0.6'),
49
+ false,
50
+ )))
51
+ )
52
+ },
53
+ apply: async ({ manifestFile }) => {
54
+ // Make sure we catch all variants; we could load the manifest
55
+ // and replace the values in the data structures here; unfortunately
56
+ // writing that back to the file messes with the formatting more than
57
+ // we'd like; that's why for now, we use a simple patching approach
58
+ await toolbox.patching.replace(
59
+ manifestFile,
60
+ new RegExp('apiVersion: 0.0.6', 'g'),
61
+ 'apiVersion: 0.0.7',
62
+ )
63
+ await toolbox.patching.replace(
64
+ manifestFile,
65
+ new RegExp("apiVersion: '0.0.6'", 'g'),
66
+ "apiVersion: '0.0.7'",
67
+ )
68
+ await toolbox.patching.replace(
69
+ manifestFile,
70
+ new RegExp('apiVersion: "0.0.6"', 'g'),
71
+ 'apiVersion: "0.0.7"',
72
+ )
73
+ },
74
+ }
@@ -6,7 +6,7 @@ const { loadManifest } = require('./util/load-manifest')
6
6
  // Spec version to 0.0.2 uses top level templates. graph-cli no longer supports
7
7
  // 0.0.1 which used nested templates.
8
8
  module.exports = {
9
- name: 'Bump mapping specVersion from 0.0.1 to 0.0.2',
9
+ name: 'Bump manifest specVersion from 0.0.1 to 0.0.2',
10
10
  predicate: async ({ sourceDir, manifestFile }) => {
11
11
  let manifest = await loadManifest(manifestFile)
12
12
  return (
@@ -0,0 +1,29 @@
1
+ const fs = require('fs-extra')
2
+ const toolbox = require('gluegun/toolbox')
3
+ const yaml = require('js-yaml')
4
+ const { loadManifest } = require('./util/load-manifest')
5
+
6
+ // Spec version 0.0.4 uses feature management, but features are
7
+ // detected and validated by the graph-node instance during subgraph
8
+ // deployment.
9
+ //
10
+ // Also, we skip spec version 0.0.3, which is considered invalid and
11
+ // non-canonical.
12
+ module.exports = {
13
+ name: 'Bump manifest specVersion from 0.0.2 to 0.0.4',
14
+ predicate: async ({ sourceDir, manifestFile }) => {
15
+ let manifest = await loadManifest(manifestFile)
16
+ return (
17
+ manifest &&
18
+ typeof manifest === 'object' &&
19
+ manifest.specVersion &&
20
+ (manifest.specVersion === '0.0.2' || manifest.specVersion === '0.0.3')
21
+ )
22
+ },
23
+ apply: async ({ manifestFile }) => {
24
+ await toolbox.patching.patch(manifestFile, {
25
+ insert: 'specVersion: 0.0.4',
26
+ replace: new RegExp(`specVersion: ['"]?0.0.[23]['"]?`),
27
+ })
28
+ },
29
+ }
@@ -0,0 +1,25 @@
1
+ const fs = require('fs-extra')
2
+ const toolbox = require('gluegun/toolbox')
3
+ const yaml = require('js-yaml')
4
+ const { loadManifest } = require('./util/load-manifest')
5
+
6
+ // Spec version 0.0.5 let event handlers require transaction receipt
7
+ // data to be accessed in the runtime.
8
+ module.exports = {
9
+ name: 'Bump manifest specVersion from 0.0.4 to 0.0.5',
10
+ predicate: async ({ sourceDir, manifestFile }) => {
11
+ let manifest = await loadManifest(manifestFile)
12
+ return (
13
+ manifest &&
14
+ typeof manifest === 'object' &&
15
+ manifest.specVersion &&
16
+ manifest.specVersion === '0.0.4'
17
+ )
18
+ },
19
+ apply: async ({ manifestFile }) => {
20
+ await toolbox.patching.patch(manifestFile, {
21
+ insert: 'specVersion: 0.0.5',
22
+ replace: new RegExp(`specVersion: ['"]?0.0.4['"]?`),
23
+ })
24
+ },
25
+ }
package/src/migrations.js CHANGED
@@ -5,7 +5,11 @@ const MIGRATIONS = [
5
5
  require('./migrations/mapping_api_version_0_0_2'),
6
6
  require('./migrations/mapping_api_version_0_0_3'),
7
7
  require('./migrations/mapping_api_version_0_0_4'),
8
+ require('./migrations/mapping_api_version_0_0_5'),
9
+ require('./migrations/mapping_api_version_0_0_6'),
8
10
  require('./migrations/spec_version_0_0_2'),
11
+ require('./migrations/spec_version_0_0_3'),
12
+ require('./migrations/spec_version_0_0_4'),
9
13
  ]
10
14
 
11
15
  const applyMigrations = async options =>
@@ -7,6 +7,7 @@
7
7
  scalar String
8
8
  scalar File
9
9
  scalar BigInt
10
+ scalar Boolean
10
11
 
11
12
  type SubgraphManifest {
12
13
  specVersion: String!
@@ -72,6 +73,7 @@ type ContractEventHandler {
72
73
  event: String!
73
74
  topic0: String
74
75
  handler: String!
76
+ receipt: Boolean
75
77
  }
76
78
 
77
79
  type Graft {
@@ -19,7 +19,7 @@ module.exports = class Protocol {
19
19
  }
20
20
 
21
21
  constructor(name) {
22
- this.name = this.normalizeName(name)
22
+ this.name = Protocol.normalizeName(name)
23
23
  }
24
24
 
25
25
  static availableProtocols() {
@@ -67,7 +67,7 @@ module.exports = class Protocol {
67
67
  })
68
68
  }
69
69
 
70
- normalizeName(name) {
70
+ static normalizeName(name) {
71
71
  return Protocol.availableProtocols().findKey(possibleNames =>
72
72
  possibleNames.includes(name),
73
73
  )
@@ -50,7 +50,7 @@ module.exports = class Scaffold {
50
50
  },
51
51
  dependencies: {
52
52
  '@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
53
- '@graphprotocol/graph-ts': `0.26.0`,
53
+ '@graphprotocol/graph-ts': `0.27.0-alpha.1`,
54
54
  },
55
55
  }),
56
56
  { parser: 'json' },
@@ -2,6 +2,8 @@ const immutable = require('immutable')
2
2
  const yaml = require('js-yaml')
3
3
  const path = require('path')
4
4
 
5
+ const Protocol = require('../protocols')
6
+
5
7
  const List = immutable.List
6
8
  const Map = immutable.Map
7
9
 
@@ -204,6 +206,18 @@ const validators = immutable.fromJS({
204
206
  message: `Expected filename, found ${typeName(value)}:\n${value}`,
205
207
  },
206
208
  ]),
209
+
210
+ Boolean: (value, ctx) =>
211
+ typeof value === 'boolean'
212
+ ? List()
213
+ : immutable.fromJS([
214
+ {
215
+ path: ctx.get('path'),
216
+ message: `Expected true or false, found ${typeName(value)}:\n${toYAML(
217
+ value,
218
+ )}`,
219
+ },
220
+ ]),
207
221
  })
208
222
 
209
223
  const validateValue = (value, ctx) => {
@@ -229,23 +243,61 @@ const validateValue = (value, ctx) => {
229
243
  }
230
244
  }
231
245
 
232
- const validateDataSourceForNetwork = (dataSources, protocol) =>
246
+ // Transforms list of data sources like this:
247
+ // [
248
+ // { name: 'contract0', kind: 'ethereum/contract', network: 'mainnet' },
249
+ // { name: 'contract1', kind: 'ethereum', network: 'mainnet' },
250
+ // { name: 'contract2', kind: 'ethereum/contract', network: 'xdai' },
251
+ // { name: 'contract3', kind: 'near', network: 'near-mainnet' },
252
+ // ]
253
+ //
254
+ // Into Immutable JS structure like this (protocol kind is normalized):
255
+ // {
256
+ // ethereum: {
257
+ // mainnet: ['contract0', 'contract1'],
258
+ // xdai: ['contract2'],
259
+ // },
260
+ // near: {
261
+ // 'near-mainnet': ['contract3'],
262
+ // },
263
+ // }
264
+ const dataSourceListToMap = dataSources =>
233
265
  dataSources
234
- .filter(dataSource => protocol.isValidKindName(dataSource.kind))
235
266
  .reduce(
236
- (networks, dataSource) =>
237
- networks.update(dataSource.network, dataSources =>
238
- (dataSources || immutable.OrderedSet()).add(dataSource.name),
267
+ (protocolKinds, dataSource) =>
268
+ protocolKinds.update(Protocol.normalizeName(dataSource.kind), networks =>
269
+ (networks || immutable.OrderedMap()).update(dataSource.network, dataSourceNames =>
270
+ (dataSourceNames || immutable.OrderedSet()).add(dataSource.name)),
239
271
  ),
240
272
  immutable.OrderedMap(),
241
273
  )
242
274
 
243
- const validateDataSourceNetworks = (value, protocol) => {
275
+ const validateDataSourceProtocolAndNetworks = value => {
244
276
  const dataSources = [...value.dataSources, ...(value.templates || [])]
245
277
 
246
- // Networks found valid for a protocol.
247
- // By searching through all data sources and templates.
248
- const networks = validateDataSourceForNetwork(dataSources, protocol)
278
+ const protocolNetworkMap = dataSourceListToMap(dataSources)
279
+
280
+ if (protocolNetworkMap.size > 1) {
281
+ return immutable.fromJS([
282
+ {
283
+ path: [],
284
+ message: `Conflicting protocol kinds used in data sources and templates:
285
+ ${protocolNetworkMap
286
+ .map(
287
+ (dataSourceNames, protocolKind) =>
288
+ ` ${
289
+ protocolKind === undefined
290
+ ? 'Data sources and templates having no protocol kind set'
291
+ : `Data sources and templates using '${protocolKind}'`
292
+ }:\n${dataSourceNames.valueSeq().flatten().map(ds => ` - ${ds}`).join('\n')}`,
293
+ )
294
+ .join('\n')}
295
+ Recommendation: Make all data sources and templates use the same protocol kind.`,
296
+ },
297
+ ])
298
+ }
299
+
300
+ const networks = protocolNetworkMap.first()
249
301
 
250
302
  if (networks.size > 1) {
251
303
  return immutable.fromJS([
@@ -298,9 +350,9 @@ const validateManifest = (value, type, schema, protocol, { resolveFile }) => {
298
350
  return errors
299
351
  }
300
352
 
301
- // Validate that all data sources are for the same `network` (this includes
302
- // _no_ network at all)
303
- return validateDataSourceNetworks(value, protocol)
353
+ // Validate that all data sources are for the same `network` and `protocol` (kind)
354
+ // (this includes _no_ network/protocol at all)
355
+ return validateDataSourceProtocolAndNetworks(value)
304
356
  }
305
357
 
306
358
  module.exports = {
@@ -0,0 +1 @@
1
+ *.sol linguist-language=Solidity
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 The Graph
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # Example Subgraph
2
+
3
+ An example to help you get started with The Graph. For more information see the docs on https://thegraph.com/docs/.
@@ -0,0 +1 @@
1
+ [{"constant":false,"inputs":[{"name":"_imageUrl","type":"string"}],"name":"updateGravatarImage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"setMythicalGravatar","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"getGravatar","outputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"gravatarToOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"ownerToGravatar","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_displayName","type":"string"}],"name":"updateGravatarName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_displayName","type":"string"},{"name":"_imageUrl","type":"string"}],"name":"createGravatar","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"gravatars","outputs":[{"name":"owner","type":"address"},{"name":"displayName","type":"string"},{"name":"imageUrl","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"displayName","type":"string"},{"indexed":false,"name":"imageUrl","type":"string"}],"name":"NewGravatar","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"displayName","type":"string"},{"indexed":false,"name":"imageUrl","type":"string"}],"name":"UpdatedGravatar","type":"event"}]
@@ -0,0 +1 @@
1
+ 60806040526000808190555060f5806100196000396000f3fe6080604052600436106043576000357c0100000000000000000000000000000000000000000000000000000000900480633fa4f245146048578063d09de08a146070575b600080fd5b348015605357600080fd5b50605a6078565b6040518082815260200191505060405180910390f35b6076607e565b005b60005481565b600160008082825401925050819055507f20d8a6f5a693f9d1d627a598e8820f7a55ee74c183aa8f1a30e8d4e8dd9a8d846000546040518082815260200191505060405180910390a156fea165627a7a72305820fca3d11af59a6ac98027ec3bebdb10711f195860d6d9abd07921c88c8c50228f0029
@@ -0,0 +1,63 @@
1
+ pragma solidity ^0.4.0;
2
+
3
+ contract GravatarRegistry {
4
+ event NewGravatar(uint id, address owner, string displayName, string imageUrl);
5
+ event UpdatedGravatar(uint id, address owner, string displayName, string imageUrl);
6
+
7
+ struct Gravatar {
8
+ address owner;
9
+ string displayName;
10
+ string imageUrl;
11
+ }
12
+
13
+ Gravatar[] public gravatars;
14
+
15
+ mapping (uint => address) public gravatarToOwner;
16
+ mapping (address => uint) public ownerToGravatar;
17
+
18
+ function createGravatar(string _displayName, string _imageUrl) public {
19
+ require(ownerToGravatar[msg.sender] == 0);
20
+ uint id = gravatars.push(Gravatar(msg.sender, _displayName, _imageUrl)) - 1;
21
+
22
+ gravatarToOwner[id] = msg.sender;
23
+ ownerToGravatar[msg.sender] = id;
24
+
25
+ emit NewGravatar(id, msg.sender, _displayName, _imageUrl);
26
+ }
27
+
28
+ function getGravatar(address owner) public view returns (string, string) {
29
+ uint id = ownerToGravatar[owner];
30
+ return (gravatars[id].displayName, gravatars[id].imageUrl);
31
+ }
32
+
33
+ function updateGravatarName(string _displayName) public {
34
+ require(ownerToGravatar[msg.sender] != 0);
35
+ require(msg.sender == gravatars[ownerToGravatar[msg.sender]].owner);
36
+
37
+ uint id = ownerToGravatar[msg.sender];
38
+
39
+ gravatars[id].displayName = _displayName;
40
+ emit UpdatedGravatar(id, msg.sender, _displayName, gravatars[id].imageUrl);
41
+ }
42
+
43
+ function updateGravatarImage(string _imageUrl) public {
44
+ require(ownerToGravatar[msg.sender] != 0);
45
+ require(msg.sender == gravatars[ownerToGravatar[msg.sender]].owner);
46
+
47
+ uint id = ownerToGravatar[msg.sender];
48
+
49
+ gravatars[id].imageUrl = _imageUrl;
50
+ emit UpdatedGravatar(id, msg.sender, gravatars[id].displayName, _imageUrl);
51
+ }
52
+
53
+ // the gravatar at position 0 of gravatars[]
54
+ // is fake
55
+ // it's a mythical gravatar
56
+ // that doesn't really exist
57
+ // dani will invoke this function once when this contract is deployed
58
+ // but then no more
59
+ function setMythicalGravatar() public {
60
+ require(msg.sender == 0x8d3e809Fbd258083a5Ba004a527159Da535c8abA);
61
+ gravatars.push(Gravatar(0x0, " ", " "));
62
+ }
63
+ }
@@ -0,0 +1,23 @@
1
+ pragma solidity ^0.4.0;
2
+
3
+ contract Migrations {
4
+ address public owner;
5
+ uint public last_completed_migration;
6
+
7
+ constructor() public {
8
+ owner = msg.sender;
9
+ }
10
+
11
+ modifier restricted() {
12
+ if (msg.sender == owner) _;
13
+ }
14
+
15
+ function setCompleted(uint completed) public restricted {
16
+ last_completed_migration = completed;
17
+ }
18
+
19
+ function upgrade(address new_address) public restricted {
20
+ Migrations upgraded = Migrations(new_address);
21
+ upgraded.setCompleted(last_completed_migration);
22
+ }
23
+ }
@@ -0,0 +1,39 @@
1
+ version: '3'
2
+ services:
3
+ graph-node:
4
+ image: graphprotocol/graph-node:v0.22.0
5
+ ports:
6
+ - '8000:8000'
7
+ - '8001:8001'
8
+ - '8020:8020'
9
+ - '8030:8030'
10
+ - '8040:8040'
11
+ depends_on:
12
+ - ipfs
13
+ - postgres
14
+ environment:
15
+ postgres_host: postgres
16
+ postgres_user: graph-node
17
+ postgres_pass: let-me-in
18
+ postgres_db: graph-node
19
+ ipfs: 'ipfs:5001'
20
+ # Change next line if you want to connect to a different JSON-RPC endpoint
21
+ ethereum: 'mainnet:http://host.docker.internal:8545'
22
+ GRAPH_LOG: info
23
+ ipfs:
24
+ image: ipfs/go-ipfs:v0.4.23
25
+ ports:
26
+ - '5001:5001'
27
+ volumes:
28
+ - ./data/ipfs:/data/ipfs
29
+ postgres:
30
+ image: postgres
31
+ ports:
32
+ - '5432:5432'
33
+ command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"]
34
+ environment:
35
+ POSTGRES_USER: graph-node
36
+ POSTGRES_PASSWORD: let-me-in
37
+ POSTGRES_DB: graph-node
38
+ volumes:
39
+ - ./data/postgres:/var/lib/postgresql/data
@@ -0,0 +1,5 @@
1
+ var Migrations = artifacts.require('./Migrations.sol')
2
+
3
+ module.exports = function(deployer) {
4
+ deployer.deploy(Migrations)
5
+ }
@@ -0,0 +1,5 @@
1
+ const GravatarRegistry = artifacts.require('./GravatarRegistry.sol')
2
+
3
+ module.exports = async function(deployer) {
4
+ await deployer.deploy(GravatarRegistry)
5
+ }
@@ -0,0 +1,15 @@
1
+ const GravatarRegistry = artifacts.require('./GravatarRegistry.sol')
2
+
3
+ module.exports = async function(deployer) {
4
+ const registry = await GravatarRegistry.deployed()
5
+
6
+ console.log('Account address:', registry.address)
7
+
8
+ let accounts = await web3.eth.getAccounts()
9
+ await registry.createGravatar('Carl', 'https://thegraph.com/img/team/team_04.png', {
10
+ from: accounts[0],
11
+ })
12
+ await registry.createGravatar('Lucas', 'https://thegraph.com/img/team/bw_Lucas.jpg', {
13
+ from: accounts[1],
14
+ })
15
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "mainnet": {
3
+ "Gravity": {
4
+ "address": "0x2E645469f354BB4F5c8a05B3b30A929361cf77eC"
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "example-subgraph",
3
+ "version": "0.1.0",
4
+ "scripts": {
5
+ "build-contract": "solc contracts/Gravity.sol --abi -o abis --overwrite && solc contracts/Gravity.sol --bin -o bin --overwrite",
6
+ "create": "graph create user/example-subgraph --node https://api.thegraph.com/deploy/",
7
+ "create-local": "graph create user/example-subgraph --node http://127.0.0.1:8020",
8
+ "codegen": "graph codegen",
9
+ "build": "graph build",
10
+ "deploy": "graph deploy user/example-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/",
11
+ "deploy-local": "graph deploy user/example-subgraph --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020"
12
+ },
13
+ "devDependencies": {
14
+ "@graphprotocol/graph-ts": "^0.26.0"
15
+ },
16
+ "dependencies": {
17
+ "babel-polyfill": "^6.26.0",
18
+ "babel-register": "^6.26.0",
19
+ "truffle": "^5.0.4",
20
+ "truffle-contract": "^4.0.5",
21
+ "truffle-hdwallet-provider": "^1.0.4"
22
+ }
23
+ }
@@ -0,0 +1,6 @@
1
+ type Gravatar @entity {
2
+ id: ID!
3
+ owner: Bytes!
4
+ displayName: String!
5
+ imageUrl: String!
6
+ }
@@ -0,0 +1,22 @@
1
+ import { NewGravatar, UpdatedGravatar } from '../generated/Gravity/Gravity'
2
+ import { Gravatar } from '../generated/schema'
3
+
4
+ export function handleNewGravatar(event: NewGravatar): void {
5
+ let gravatar = new Gravatar(event.params.id.toHex())
6
+ gravatar.owner = event.params.owner
7
+ gravatar.displayName = event.params.displayName
8
+ gravatar.imageUrl = event.params.imageUrl
9
+ gravatar.save()
10
+ }
11
+
12
+ export function handleUpdatedGravatar(event: UpdatedGravatar): void {
13
+ let id = event.params.id.toHex()
14
+ let gravatar = Gravatar.load(id)
15
+ if (gravatar == null) {
16
+ gravatar = new Gravatar(id)
17
+ }
18
+ gravatar.owner = event.params.owner
19
+ gravatar.displayName = event.params.displayName
20
+ gravatar.imageUrl = event.params.imageUrl
21
+ gravatar.save()
22
+ }
@@ -0,0 +1,27 @@
1
+ specVersion: 0.0.2
2
+ description: Gravatar for Ethereum
3
+ repository: https://github.com/graphprotocol/example-subgraph
4
+ schema:
5
+ file: ./schema.graphql
6
+ dataSources:
7
+ - kind: ethereum/contract
8
+ name: Gravity
9
+ network: mainnet
10
+ source:
11
+ address: '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC'
12
+ abi: Gravity
13
+ mapping:
14
+ kind: ethereum/events
15
+ apiVersion: 0.0.5
16
+ language: wasm/assemblyscript
17
+ entities:
18
+ - Gravatar
19
+ abis:
20
+ - name: Gravity
21
+ file: ./abis/Gravity.json
22
+ eventHandlers:
23
+ - event: NewGravatar(uint256,address,string,string)
24
+ handler: handleNewGravatar
25
+ - event: UpdatedGravatar(uint256,address,string,string)
26
+ handler: handleUpdatedGravatar
27
+ file: ./src/mapping.ts
@@ -0,0 +1,27 @@
1
+ require('babel-register')
2
+ require('babel-polyfill')
3
+ const HDWalletProvider = require('truffle-hdwallet-provider')
4
+
5
+ module.exports = {
6
+ networks: {
7
+ development: {
8
+ host: '127.0.0.1',
9
+ port: 8545,
10
+ network_id: '*',
11
+ },
12
+ ropsten: {
13
+ provider: function() {
14
+ return new HDWalletProvider(
15
+ process.env.MNEMONIC,
16
+ `https://ropsten.infura.io/v3/${process.env.ROPSTEN_INFURA_API_KEY}`
17
+ )
18
+ },
19
+ network_id: '3',
20
+ },
21
+ },
22
+ compilers: {
23
+ solc: {
24
+ version: '0.4.25' // Fetch exact version from solc-bin (default: truffle's version)
25
+ }
26
+ }
27
+ }