@graphprotocol/graph-cli 0.26.1 → 0.27.2
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/package.json +4 -4
- package/examples/basic-event-handlers/yarn.lock +8 -8
- package/package.json +27 -24
- package/src/commands/deploy.js +3 -1
- package/src/commands/init.js +2 -0
- package/src/commands/test.js +82 -59
- package/src/protocols/ethereum/codegen/abi.js +77 -2
- package/src/protocols/ethereum/manifest.graphql +92 -0
- package/src/protocols/index.js +17 -7
- package/src/protocols/near/manifest.graphql +57 -0
- package/src/subgraph.js +18 -13
- package/src/validation/manifest.js +12 -8
- package/tests/cli/init/ethereum/from-example/.gitattributes +1 -0
- package/tests/cli/init/ethereum/from-example/LICENSE +21 -0
- package/tests/cli/init/ethereum/from-example/README.md +3 -0
- package/tests/cli/init/ethereum/from-example/abis/Gravity.json +1 -0
- package/tests/cli/init/ethereum/from-example/bin/Counter.bin +1 -0
- package/tests/cli/init/ethereum/from-example/contracts/Gravity.sol +63 -0
- package/tests/cli/init/ethereum/from-example/contracts/Migrations.sol +23 -0
- package/tests/cli/init/ethereum/from-example/docker-compose.yml +39 -0
- package/tests/cli/init/ethereum/from-example/migrations/1_initial_migration.js +5 -0
- package/tests/cli/init/ethereum/from-example/migrations/2_deploy_contract.js +5 -0
- package/tests/cli/init/ethereum/from-example/migrations/3_create_gravatars.js +15 -0
- package/tests/cli/init/ethereum/from-example/networks.json +7 -0
- package/tests/cli/init/ethereum/from-example/package.json +23 -0
- package/tests/cli/init/ethereum/from-example/schema.graphql +6 -0
- package/tests/cli/init/ethereum/from-example/src/mapping.ts +22 -0
- package/tests/cli/init/ethereum/from-example/subgraph.yaml +27 -0
- package/tests/cli/init/ethereum/from-example/truffle.js +27 -0
- package/tests/cli/init/ethereum/from-example/yarn.lock +5977 -0
- package/tests/cli/validation/example-values-found.stderr +2 -2
- package/tests/cli/validation/invalid-manifest/subgraph.yaml +2 -1
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +12 -0
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +5 -0
- package/tests/cli/validation/invalid-manifest.stderr +0 -3
- package/tests/cli/validation.test.js +8 -0
- package/manifest-schema.graphql +0 -122
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
account: String
|
|
34
|
+
startBlock: BigInt
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type ContractMapping {
|
|
38
|
+
apiVersion: String!
|
|
39
|
+
language: String!
|
|
40
|
+
file: File!
|
|
41
|
+
entities: [String!]!
|
|
42
|
+
blockHandlers: [BlockHandler!]
|
|
43
|
+
receiptHandlers: [ReceiptHandler!]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type BlockHandler {
|
|
47
|
+
handler: String!
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type ReceiptHandler {
|
|
51
|
+
handler: String!
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type Graft {
|
|
55
|
+
base: String!
|
|
56
|
+
block: BigInt!
|
|
57
|
+
}
|
package/src/subgraph.js
CHANGED
|
@@ -27,7 +27,7 @@ const buildCombinedWarning = (filename, warnings) =>
|
|
|
27
27
|
? warnings.reduce(
|
|
28
28
|
(msg, w) =>
|
|
29
29
|
`${msg}
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
Path: ${w.get('path').size === 0 ? '/' : w.get('path').join(' > ')}
|
|
32
32
|
${w
|
|
33
33
|
.get('message')
|
|
@@ -39,9 +39,21 @@ const buildCombinedWarning = (filename, warnings) =>
|
|
|
39
39
|
|
|
40
40
|
module.exports = class Subgraph {
|
|
41
41
|
static async validate(data, protocol, { resolveFile }) {
|
|
42
|
+
if (protocol.name == null) {
|
|
43
|
+
return immutable.fromJS([
|
|
44
|
+
{
|
|
45
|
+
path: [],
|
|
46
|
+
message: `Unable to determine for which protocol manifest file is built for. Ensure you have at least one 'dataSources' and/or 'templates' elements defined in your subgraph.`,
|
|
47
|
+
},
|
|
48
|
+
])
|
|
49
|
+
}
|
|
50
|
+
|
|
42
51
|
// Parse the default subgraph schema
|
|
43
52
|
let schema = graphql.parse(
|
|
44
|
-
await fs.readFile(
|
|
53
|
+
await fs.readFile(
|
|
54
|
+
path.join(__dirname, 'protocols', protocol.name, `manifest.graphql`),
|
|
55
|
+
'utf-8',
|
|
56
|
+
),
|
|
45
57
|
)
|
|
46
58
|
|
|
47
59
|
// Obtain the root `SubgraphManifest` type from the schema
|
|
@@ -146,10 +158,7 @@ At least one such handler must be defined.`,
|
|
|
146
158
|
}
|
|
147
159
|
|
|
148
160
|
static validateContractValues(manifest, protocol) {
|
|
149
|
-
return validation.validateContractValues(
|
|
150
|
-
manifest,
|
|
151
|
-
protocol,
|
|
152
|
-
)
|
|
161
|
+
return validation.validateContractValues(manifest, protocol)
|
|
153
162
|
}
|
|
154
163
|
|
|
155
164
|
// Validate that data source names are unique, so they don't overwrite each other.
|
|
@@ -200,17 +209,13 @@ More than one template named '${name}', template names must be unique.`,
|
|
|
200
209
|
return yaml.stringify(manifest.toJS())
|
|
201
210
|
}
|
|
202
211
|
|
|
203
|
-
static async load(
|
|
204
|
-
filename,
|
|
205
|
-
{ protocol, skipValidation } = { skipValidation: false }
|
|
206
|
-
) {
|
|
212
|
+
static async load(filename, { protocol, skipValidation } = { skipValidation: false }) {
|
|
207
213
|
// Load and validate the manifest
|
|
208
214
|
let data = null
|
|
209
215
|
|
|
210
|
-
if(filename.match(/.js$/)) {
|
|
216
|
+
if (filename.match(/.js$/)) {
|
|
211
217
|
data = require(path.resolve(filename))
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
218
|
+
} else {
|
|
214
219
|
data = yaml.parse(await fs.readFile(filename, 'utf-8'))
|
|
215
220
|
}
|
|
216
221
|
|
|
@@ -52,8 +52,7 @@ const validators = immutable.fromJS({
|
|
|
52
52
|
validators.get(ctx.getIn(['type', 'name', 'value']))(value, ctx),
|
|
53
53
|
|
|
54
54
|
UnionTypeDefinition: (value, ctx) => {
|
|
55
|
-
const unionVariants = ctx
|
|
56
|
-
.getIn(['type', 'types'])
|
|
55
|
+
const unionVariants = ctx.getIn(['type', 'types'])
|
|
57
56
|
|
|
58
57
|
let errors = List()
|
|
59
58
|
|
|
@@ -78,7 +77,10 @@ const validators = immutable.fromJS({
|
|
|
78
77
|
|
|
79
78
|
NonNullType: (value, ctx) =>
|
|
80
79
|
value !== null && value !== undefined
|
|
81
|
-
? validateValue(
|
|
80
|
+
? validateValue(
|
|
81
|
+
value,
|
|
82
|
+
ctx.update('type', type => type.get('type')),
|
|
83
|
+
)
|
|
82
84
|
: immutable.fromJS([
|
|
83
85
|
{
|
|
84
86
|
path: ctx.get('path'),
|
|
@@ -126,7 +128,7 @@ const validators = immutable.fromJS({
|
|
|
126
128
|
),
|
|
127
129
|
)
|
|
128
130
|
: errors.push(
|
|
129
|
-
key == 'templates'
|
|
131
|
+
key == 'templates' && ctx.get('protocol').hasTemplates()
|
|
130
132
|
? immutable.fromJS({
|
|
131
133
|
path: ctx.get('path'),
|
|
132
134
|
message:
|
|
@@ -211,7 +213,8 @@ const validateValue = (value, ctx) => {
|
|
|
211
213
|
}
|
|
212
214
|
|
|
213
215
|
const validateDataSourceForNetwork = (dataSources, protocol) =>
|
|
214
|
-
dataSources
|
|
216
|
+
dataSources
|
|
217
|
+
.filter(dataSource => protocol.isValidKindName(dataSource.kind))
|
|
215
218
|
.reduce(
|
|
216
219
|
(networks, dataSource) =>
|
|
217
220
|
networks.update(dataSource.network, dataSources =>
|
|
@@ -235,11 +238,11 @@ const validateDataSourceNetworks = (value, protocol) => {
|
|
|
235
238
|
${networks
|
|
236
239
|
.map(
|
|
237
240
|
(dataSources, network) =>
|
|
238
|
-
|
|
241
|
+
` ${
|
|
239
242
|
network === undefined
|
|
240
243
|
? 'Data sources and templates having no network set'
|
|
241
|
-
|
|
242
|
-
|
|
244
|
+
: `Data sources and templates using '${network}'`
|
|
245
|
+
}:\n${dataSources.map(ds => ` - ${ds}`).join('\n')}`,
|
|
243
246
|
)
|
|
244
247
|
.join('\n')}
|
|
245
248
|
Recommendation: Make all data sources and templates use the same network name.`,
|
|
@@ -262,6 +265,7 @@ const validateManifest = (value, type, schema, protocol, { resolveFile }) => {
|
|
|
262
265
|
path: [],
|
|
263
266
|
errors: [],
|
|
264
267
|
resolveFile,
|
|
268
|
+
protocol,
|
|
265
269
|
}),
|
|
266
270
|
)
|
|
267
271
|
: immutable.fromJS([
|
|
@@ -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 @@
|
|
|
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,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,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,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
|
+
}
|