@graphprotocol/graph-cli 0.29.2 → 0.30.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/node_modules/@graphprotocol/graph-ts/chain/arweave.ts +76 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/cosmos.ts +341 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +39 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +286 -142
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +4 -2
- 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 +4 -2
- package/examples/basic-event-handlers/node_modules/keccak/build/config.gypi +300 -125
- package/examples/basic-event-handlers/node_modules/websocket/build/config.gypi +292 -15
- 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/resources/test/docker-compose.yml +4 -2
- package/src/codegen/schema.js +5 -1
- package/src/codegen/schema.test.js +102 -0
- package/src/command-helpers/abi.js +69 -0
- package/src/command-helpers/scaffold.js +67 -0
- package/src/commands/add.js +198 -0
- package/src/commands/deploy.js +0 -5
- package/src/commands/init.js +25 -71
- package/src/migrations/mapping_api_version_0_0_5.js +1 -1
- package/src/migrations/mapping_api_version_0_0_6.js +74 -0
- package/src/migrations/spec_version_0_0_2.js +1 -1
- package/src/migrations/spec_version_0_0_3.js +29 -0
- package/src/migrations/spec_version_0_0_4.js +25 -0
- package/src/migrations.js +4 -0
- package/src/protocols/arweave/manifest.graphql +57 -0
- package/src/protocols/arweave/scaffold/manifest.js +19 -0
- package/src/protocols/arweave/scaffold/mapping.js +53 -0
- package/src/protocols/arweave/subgraph.js +20 -0
- package/src/protocols/{tendermint → cosmos}/manifest.graphql +6 -0
- package/src/protocols/cosmos/scaffold/manifest.js +16 -0
- package/src/protocols/cosmos/scaffold/mapping.js +39 -0
- package/src/protocols/{tendermint → cosmos}/subgraph.js +2 -1
- package/src/protocols/ethereum/codegen/abi.js +12 -0
- package/src/protocols/ethereum/manifest.graphql +2 -0
- package/src/protocols/ethereum/scaffold/manifest.js +2 -1
- package/src/protocols/index.js +53 -20
- package/src/protocols/near/manifest.graphql +1 -0
- package/src/protocols/near/scaffold/manifest.js +4 -2
- package/src/scaffold/cosmos.test.js +86 -0
- package/src/scaffold/ethereum.test.js +2 -1
- package/src/scaffold/index.js +5 -3
- package/src/scaffold/near.test.js +2 -1
- package/src/validation/manifest.js +64 -12
- package/src/validation/schema.js +2 -0
- package/tests/cli/validation/conflicting-protocol-names/Abi.json +7 -0
- package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-protocol-names/schema.graphql +3 -0
- package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +41 -0
- package/tests/cli/validation/conflicting-protocol-names.stderr +10 -0
- package/tests/cli/validation.test.js +9 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/tendermint.ts +0 -554
- package/examples/basic-event-handlers/node_modules/keccak/build/Makefile +0 -342
- package/examples/basic-event-handlers/node_modules/keccak/build/Release/.deps/Release/obj.target/keccak/src/addon.o.d.raw +0 -27
- package/examples/basic-event-handlers/node_modules/keccak/build/binding.Makefile +0 -6
- package/examples/basic-event-handlers/node_modules/keccak/build/gyp-mac-tool +0 -615
- package/examples/basic-event-handlers/node_modules/keccak/build/keccak.target.mk +0 -209
- package/examples/basic-event-handlers/node_modules/websocket/build/Makefile +0 -347
- package/examples/basic-event-handlers/node_modules/websocket/build/Release/.deps/Release/obj.target/bufferutil/src/bufferutil.o.d.raw +0 -25
- package/examples/basic-event-handlers/node_modules/websocket/build/binding.Makefile +0 -6
- package/examples/basic-event-handlers/node_modules/websocket/build/bufferutil.target.mk +0 -192
- package/examples/basic-event-handlers/node_modules/websocket/build/gyp-mac-tool +0 -615
- package/examples/basic-event-handlers/node_modules/websocket/build/validation.target.mk +0 -192
- package/src/codegen/types/defaults.js +0 -34
- package/tests/cli/init/ethereum/from-example/.gitattributes +0 -1
- package/tests/cli/init/ethereum/from-example/LICENSE +0 -21
- package/tests/cli/init/ethereum/from-example/README.md +0 -3
- package/tests/cli/init/ethereum/from-example/abis/Gravity.json +0 -1
- package/tests/cli/init/ethereum/from-example/bin/Counter.bin +0 -1
- package/tests/cli/init/ethereum/from-example/contracts/Gravity.sol +0 -63
- package/tests/cli/init/ethereum/from-example/contracts/Migrations.sol +0 -23
- package/tests/cli/init/ethereum/from-example/docker-compose.yml +0 -39
- package/tests/cli/init/ethereum/from-example/migrations/1_initial_migration.js +0 -5
- package/tests/cli/init/ethereum/from-example/migrations/2_deploy_contract.js +0 -5
- package/tests/cli/init/ethereum/from-example/migrations/3_create_gravatars.js +0 -15
- package/tests/cli/init/ethereum/from-example/networks.json +0 -7
- package/tests/cli/init/ethereum/from-example/package.json +0 -23
- package/tests/cli/init/ethereum/from-example/schema.graphql +0 -6
- package/tests/cli/init/ethereum/from-example/src/mapping.ts +0 -22
- package/tests/cli/init/ethereum/from-example/subgraph.yaml +0 -27
- package/tests/cli/init/ethereum/from-example/truffle.js +0 -27
- package/tests/cli/init/ethereum/from-example/yarn.lock +0 -5977
|
@@ -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
|
+
owner: 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
|
+
transactionHandlers: [TransactionHandler!]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type BlockHandler {
|
|
47
|
+
handler: String!
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type TransactionHandler {
|
|
51
|
+
handler: String!
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type Graft {
|
|
55
|
+
base: String!
|
|
56
|
+
block: BigInt!
|
|
57
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const source = ({ contract }) => `
|
|
2
|
+
owner: '${contract}'`
|
|
3
|
+
|
|
4
|
+
const mapping = () => `
|
|
5
|
+
apiVersion: 0.0.5
|
|
6
|
+
language: wasm/assemblyscript
|
|
7
|
+
entities:
|
|
8
|
+
- Block
|
|
9
|
+
- Transaction
|
|
10
|
+
blockHandlers:
|
|
11
|
+
- handler: handleBlock
|
|
12
|
+
transactionHandlers:
|
|
13
|
+
- handler: handleTx
|
|
14
|
+
file: ./src/mapping.ts`
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
source,
|
|
18
|
+
mapping,
|
|
19
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const generatePlaceholderHandlers = () =>
|
|
2
|
+
`
|
|
3
|
+
import { arweave, BigInt } from '@graphprotocol/graph-ts'
|
|
4
|
+
import { Block, Transaction } from '../generated/schema'
|
|
5
|
+
|
|
6
|
+
export function handleBlock(block: arweave.Block): void {
|
|
7
|
+
// Entities can be loaded from the store using a indepHash; this indepHash
|
|
8
|
+
// needs to be unique across all entities of the same type
|
|
9
|
+
let entity = Block.load(block.indepHash.toHexString())
|
|
10
|
+
|
|
11
|
+
// Entities only exist after they have been saved to the store;
|
|
12
|
+
// \`null\` checks allow to create entities on demand
|
|
13
|
+
if (!entity) {
|
|
14
|
+
entity = new Block(block.indepHash.toHexString());
|
|
15
|
+
|
|
16
|
+
// Entity fields can be set using simple assignments
|
|
17
|
+
entity.height = BigInt.fromU64(block.height)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Entities can be written to the store with \`.save()\`
|
|
21
|
+
entity.save()
|
|
22
|
+
|
|
23
|
+
// Note: If a handler doesn't require existing field values, it is faster
|
|
24
|
+
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
25
|
+
// \`new Entity(...)\`, set the fields that should be updated and save the
|
|
26
|
+
// entity back to the store. Fields that were not set or unset remain
|
|
27
|
+
// unchanged, allowing for partial updates to be applied.
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function handleTx(tb: arweave.TransactionWithBlockPtr): void {
|
|
31
|
+
const tx = tb.tx;
|
|
32
|
+
const entity = new Transaction(tx.id.toHexString());
|
|
33
|
+
|
|
34
|
+
entity.block = tb.block.indepHash;
|
|
35
|
+
entity.tx_id = tx.id;
|
|
36
|
+
entity.last_tx = tx.lastTx;
|
|
37
|
+
entity.owner = tx.owner;
|
|
38
|
+
entity.tags = saveTags(tx.id.toHexString(), tx.tags);
|
|
39
|
+
entity.data = tx.data;
|
|
40
|
+
entity.data_root = tx.dataRoot;
|
|
41
|
+
entity.data_size = tx.dataSize;
|
|
42
|
+
entity.target = tx.target;
|
|
43
|
+
entity.quantity = tx.quantity;
|
|
44
|
+
entity.signature = tx.signature;
|
|
45
|
+
entity.reward = tx.reward;
|
|
46
|
+
|
|
47
|
+
entity.save();
|
|
48
|
+
}
|
|
49
|
+
`
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
generatePlaceholderHandlers,
|
|
53
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const immutable = require('immutable')
|
|
2
|
+
|
|
3
|
+
module.exports = class ArweaveSubgraph {
|
|
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
|
+
'transactionHandlers',
|
|
18
|
+
])
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -10,6 +10,7 @@ scalar BigInt
|
|
|
10
10
|
|
|
11
11
|
type SubgraphManifest {
|
|
12
12
|
specVersion: String!
|
|
13
|
+
features: [String!]
|
|
13
14
|
schema: Schema!
|
|
14
15
|
description: String
|
|
15
16
|
repository: String
|
|
@@ -40,6 +41,11 @@ type ContractMapping {
|
|
|
40
41
|
entities: [String!]!
|
|
41
42
|
blockHandlers: [BlockHandler!]
|
|
42
43
|
eventHandlers: [EventHandler!]
|
|
44
|
+
transactionHandlers: [TransactionHandler!]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type TransactionHandler {
|
|
48
|
+
handler: String!
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
type BlockHandler {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const source = () => `
|
|
2
|
+
startBlock: 0`
|
|
3
|
+
|
|
4
|
+
const mapping = () => `
|
|
5
|
+
apiVersion: 0.0.5
|
|
6
|
+
language: wasm/assemblyscript
|
|
7
|
+
entities:
|
|
8
|
+
- ExampleEntity
|
|
9
|
+
blockHandlers:
|
|
10
|
+
- handler: handleBlock
|
|
11
|
+
file: ./src/mapping.ts`
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
source,
|
|
15
|
+
mapping,
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const generatePlaceholderHandlers = () =>
|
|
2
|
+
`
|
|
3
|
+
import { cosmos, BigInt } from '@graphprotocol/graph-ts'
|
|
4
|
+
import { ExampleEntity } from '../generated/schema'
|
|
5
|
+
|
|
6
|
+
export function handleBlock(block: cosmos.Block): void {
|
|
7
|
+
// Entities can be loaded from the store using a string ID; this ID
|
|
8
|
+
// needs to be unique across all entities of the same type
|
|
9
|
+
let entity = ExampleEntity.load(block.header.hash.toHex())
|
|
10
|
+
|
|
11
|
+
// Entities only exist after they have been saved to the store;
|
|
12
|
+
// \`null\` checks allow to create entities on demand
|
|
13
|
+
if (!entity) {
|
|
14
|
+
entity = new ExampleEntity(block.header.hash.toHex())
|
|
15
|
+
|
|
16
|
+
// Entity fields can be set using simple assignments
|
|
17
|
+
entity.count = BigInt.fromI32(0)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// BigInt and BigDecimal math are supported
|
|
21
|
+
entity.count = entity.count + BigInt.fromI32(1)
|
|
22
|
+
|
|
23
|
+
// Entity fields can be set based on receipt information
|
|
24
|
+
entity.height = block.header.height
|
|
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
|
+
`
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
generatePlaceholderHandlers,
|
|
39
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const immutable = require('immutable')
|
|
2
2
|
|
|
3
|
-
module.exports = class
|
|
3
|
+
module.exports = class CosmosSubgraph {
|
|
4
4
|
constructor(options = {}) {
|
|
5
5
|
this.manifest = options.manifest
|
|
6
6
|
this.resolveFile = options.resolveFile
|
|
@@ -15,6 +15,7 @@ module.exports = class TendermintSubgraph {
|
|
|
15
15
|
return immutable.List([
|
|
16
16
|
'blockHandlers',
|
|
17
17
|
'eventHandlers',
|
|
18
|
+
'transactionHandlers',
|
|
18
19
|
])
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -502,6 +502,18 @@ module.exports = class AbiCodeGenerator {
|
|
|
502
502
|
),
|
|
503
503
|
)
|
|
504
504
|
.forEach(member => returnType.addMember(member))
|
|
505
|
+
|
|
506
|
+
// Add getters to the type
|
|
507
|
+
outputs
|
|
508
|
+
.map((output, index) =>
|
|
509
|
+
!!output.get('name') && tsCodegen.method(
|
|
510
|
+
`get${output.get('name')[0].toUpperCase()}${output.get('name').slice(1)}`,
|
|
511
|
+
[],
|
|
512
|
+
this._getTupleParamType(output, index, tupleResultParentType),
|
|
513
|
+
`return this.value${index};`
|
|
514
|
+
)
|
|
515
|
+
)
|
|
516
|
+
.forEach(method => !!method && returnType.addMethod(method))
|
|
505
517
|
|
|
506
518
|
// Create types for Tuple outputs
|
|
507
519
|
outputs.forEach((output, index) => {
|
|
@@ -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 {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { abiEvents } = require('../../../scaffold/schema')
|
|
2
|
+
const { strings } = require('gluegun')
|
|
2
3
|
const ABI = require('../abi')
|
|
3
4
|
|
|
4
5
|
const source = ({ contract, contractName }) => `
|
|
@@ -24,7 +25,7 @@ const mapping = ({ abi, contractName }) => `
|
|
|
24
25
|
handler: handle${event.get('_alias')}`,
|
|
25
26
|
)
|
|
26
27
|
.join('')}
|
|
27
|
-
file: ./src
|
|
28
|
+
file: ./src/${strings.kebabCase(contractName)}.ts`
|
|
28
29
|
|
|
29
30
|
module.exports = {
|
|
30
31
|
source,
|
package/src/protocols/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
const immutable = require('immutable')
|
|
2
|
+
const ArweaveSubgraph = require('./arweave/subgraph')
|
|
2
3
|
const EthereumTypeGenerator = require('./ethereum/type-generator')
|
|
3
4
|
const EthereumTemplateCodeGen = require('./ethereum/codegen/template')
|
|
4
5
|
const EthereumABI = require('./ethereum/abi')
|
|
5
6
|
const EthereumSubgraph = require('./ethereum/subgraph')
|
|
6
7
|
const NearSubgraph = require('./near/subgraph')
|
|
7
|
-
const
|
|
8
|
+
const CosmosSubgraph = require('./cosmos/subgraph')
|
|
8
9
|
const EthereumContract = require('./ethereum/contract')
|
|
9
10
|
const NearContract = require('./near/contract')
|
|
10
11
|
const EthereumManifestScaffold = require('./ethereum/scaffold/manifest')
|
|
11
12
|
const NearManifestScaffold = require('./near/scaffold/manifest')
|
|
13
|
+
const CosmosManifestScaffold = require('./cosmos/scaffold/manifest')
|
|
14
|
+
const ArweaveMappingScaffold = require('./arweave/scaffold/mapping')
|
|
12
15
|
const EthereumMappingScaffold = require('./ethereum/scaffold/mapping')
|
|
13
16
|
const NearMappingScaffold = require('./near/scaffold/mapping')
|
|
17
|
+
const CosmosMappingScaffold = require('./cosmos/scaffold/mapping')
|
|
14
18
|
|
|
15
19
|
module.exports = class Protocol {
|
|
16
20
|
static fromDataSources(dataSourcesAndTemplates) {
|
|
@@ -19,21 +23,23 @@ module.exports = class Protocol {
|
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
constructor(name) {
|
|
22
|
-
this.name =
|
|
26
|
+
this.name = Protocol.normalizeName(name)
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
static availableProtocols() {
|
|
26
30
|
return immutable.fromJS({
|
|
27
31
|
// `ethereum/contract` is kept for backwards compatibility.
|
|
28
32
|
// New networks (or protocol perhaps) shouldn't have the `/contract` anymore (unless a new case makes use of it).
|
|
33
|
+
arweave: ['arweave'],
|
|
29
34
|
ethereum: ['ethereum', 'ethereum/contract'],
|
|
30
35
|
near: ['near'],
|
|
31
|
-
|
|
36
|
+
cosmos: ['cosmos']
|
|
32
37
|
})
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
static availableNetworks() {
|
|
36
41
|
return immutable.fromJS({
|
|
42
|
+
arweave: ['arweave-mainnet'],
|
|
37
43
|
ethereum: [
|
|
38
44
|
'mainnet',
|
|
39
45
|
'kovan',
|
|
@@ -63,11 +69,16 @@ module.exports = class Protocol {
|
|
|
63
69
|
'aurora-testnet',
|
|
64
70
|
],
|
|
65
71
|
near: ['near-mainnet', 'near-testnet'],
|
|
66
|
-
|
|
72
|
+
cosmos: [
|
|
73
|
+
'cosmoshub-4',
|
|
74
|
+
'theta-testnet-001',
|
|
75
|
+
'osmosis-1',
|
|
76
|
+
'osmo-test-4'
|
|
77
|
+
],
|
|
67
78
|
})
|
|
68
79
|
}
|
|
69
80
|
|
|
70
|
-
normalizeName(name) {
|
|
81
|
+
static normalizeName(name) {
|
|
71
82
|
return Protocol.availableProtocols().findKey(possibleNames =>
|
|
72
83
|
possibleNames.includes(name),
|
|
73
84
|
)
|
|
@@ -75,12 +86,14 @@ module.exports = class Protocol {
|
|
|
75
86
|
|
|
76
87
|
displayName() {
|
|
77
88
|
switch (this.name) {
|
|
89
|
+
case 'arweave':
|
|
90
|
+
return 'Arweave'
|
|
78
91
|
case 'ethereum':
|
|
79
92
|
return 'Ethereum'
|
|
80
93
|
case 'near':
|
|
81
94
|
return 'NEAR'
|
|
82
|
-
case '
|
|
83
|
-
return '
|
|
95
|
+
case 'cosmos':
|
|
96
|
+
return 'Cosmos'
|
|
84
97
|
}
|
|
85
98
|
}
|
|
86
99
|
|
|
@@ -94,55 +107,65 @@ module.exports = class Protocol {
|
|
|
94
107
|
|
|
95
108
|
hasABIs() {
|
|
96
109
|
switch (this.name) {
|
|
110
|
+
case 'arweave':
|
|
111
|
+
return false
|
|
97
112
|
case 'ethereum':
|
|
98
113
|
return true
|
|
99
114
|
case 'near':
|
|
100
115
|
return false
|
|
101
|
-
case '
|
|
116
|
+
case 'cosmos':
|
|
102
117
|
return false
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
120
|
|
|
106
121
|
hasContract() {
|
|
107
122
|
switch (this.name) {
|
|
123
|
+
case 'arweave':
|
|
124
|
+
return false
|
|
108
125
|
case 'ethereum':
|
|
109
126
|
return true
|
|
110
127
|
case 'near':
|
|
111
128
|
return true
|
|
112
|
-
case '
|
|
129
|
+
case 'cosmos':
|
|
113
130
|
return false
|
|
114
131
|
}
|
|
115
132
|
}
|
|
116
133
|
|
|
117
134
|
hasEvents() {
|
|
118
135
|
switch (this.name) {
|
|
136
|
+
case 'arweave':
|
|
137
|
+
return false
|
|
119
138
|
case 'ethereum':
|
|
120
139
|
return true
|
|
121
140
|
case 'near':
|
|
122
141
|
return false
|
|
123
|
-
case '
|
|
142
|
+
case 'cosmos':
|
|
124
143
|
return false
|
|
125
144
|
}
|
|
126
145
|
}
|
|
127
146
|
|
|
128
147
|
hasTemplates() {
|
|
129
148
|
switch (this.name) {
|
|
149
|
+
case 'arweave':
|
|
150
|
+
return false
|
|
130
151
|
case 'ethereum':
|
|
131
152
|
return true
|
|
132
153
|
case 'near':
|
|
133
154
|
return false
|
|
134
|
-
case '
|
|
155
|
+
case 'cosmos':
|
|
135
156
|
return false
|
|
136
157
|
}
|
|
137
158
|
}
|
|
138
159
|
|
|
139
160
|
getTypeGenerator(options) {
|
|
140
161
|
switch (this.name) {
|
|
162
|
+
case 'arweave':
|
|
163
|
+
return null
|
|
141
164
|
case 'ethereum':
|
|
142
165
|
return new EthereumTypeGenerator(options)
|
|
143
166
|
case 'near':
|
|
144
167
|
return null
|
|
145
|
-
case '
|
|
168
|
+
case 'cosmos':
|
|
146
169
|
return null
|
|
147
170
|
}
|
|
148
171
|
}
|
|
@@ -164,11 +187,13 @@ module.exports = class Protocol {
|
|
|
164
187
|
|
|
165
188
|
getABI() {
|
|
166
189
|
switch (this.name) {
|
|
190
|
+
case 'arweave':
|
|
191
|
+
return null
|
|
167
192
|
case 'ethereum':
|
|
168
193
|
return EthereumABI
|
|
169
194
|
case 'near':
|
|
170
195
|
return null
|
|
171
|
-
case '
|
|
196
|
+
case 'cosmos':
|
|
172
197
|
return null
|
|
173
198
|
}
|
|
174
199
|
}
|
|
@@ -177,12 +202,14 @@ module.exports = class Protocol {
|
|
|
177
202
|
const optionsWithProtocol = { ...options, protocol: this }
|
|
178
203
|
|
|
179
204
|
switch (this.name) {
|
|
205
|
+
case 'arweave':
|
|
206
|
+
return new ArweaveSubgraph(optionsWithProtocol)
|
|
180
207
|
case 'ethereum':
|
|
181
208
|
return new EthereumSubgraph(optionsWithProtocol)
|
|
182
209
|
case 'near':
|
|
183
210
|
return new NearSubgraph(optionsWithProtocol)
|
|
184
|
-
case '
|
|
185
|
-
return new
|
|
211
|
+
case 'cosmos':
|
|
212
|
+
return new CosmosSubgraph(optionsWithProtocol)
|
|
186
213
|
default:
|
|
187
214
|
throw new Error(`Data sources with kind '${this.name}' are not supported yet`)
|
|
188
215
|
}
|
|
@@ -190,34 +217,40 @@ module.exports = class Protocol {
|
|
|
190
217
|
|
|
191
218
|
getContract() {
|
|
192
219
|
switch (this.name) {
|
|
220
|
+
case 'arweave':
|
|
221
|
+
return null
|
|
193
222
|
case 'ethereum':
|
|
194
223
|
return EthereumContract
|
|
195
224
|
case 'near':
|
|
196
225
|
return NearContract
|
|
197
|
-
case '
|
|
226
|
+
case 'cosmos':
|
|
198
227
|
return null
|
|
199
228
|
}
|
|
200
229
|
}
|
|
201
230
|
|
|
202
231
|
getManifestScaffold() {
|
|
203
232
|
switch (this.name) {
|
|
233
|
+
case 'arweave':
|
|
234
|
+
return ArweaveMappingScaffold
|
|
204
235
|
case 'ethereum':
|
|
205
236
|
return EthereumManifestScaffold
|
|
206
237
|
case 'near':
|
|
207
238
|
return NearManifestScaffold
|
|
208
|
-
case '
|
|
209
|
-
return
|
|
239
|
+
case 'cosmos':
|
|
240
|
+
return CosmosManifestScaffold
|
|
210
241
|
}
|
|
211
242
|
}
|
|
212
243
|
|
|
213
244
|
getMappingScaffold() {
|
|
214
245
|
switch (this.name) {
|
|
246
|
+
case 'arweave':
|
|
247
|
+
return ArweaveMappingScaffold
|
|
215
248
|
case 'ethereum':
|
|
216
249
|
return EthereumMappingScaffold
|
|
217
250
|
case 'near':
|
|
218
251
|
return NearMappingScaffold
|
|
219
|
-
case '
|
|
220
|
-
return
|
|
252
|
+
case 'cosmos':
|
|
253
|
+
return CosmosMappingScaffold
|
|
221
254
|
}
|
|
222
255
|
}
|
|
223
256
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
const { strings } = require('gluegun')
|
|
2
|
+
|
|
1
3
|
const source = ({ contract }) => `
|
|
2
4
|
account: '${contract}'`
|
|
3
5
|
|
|
4
|
-
const mapping = () => `
|
|
6
|
+
const mapping = ({ contractName }) => `
|
|
5
7
|
apiVersion: 0.0.5
|
|
6
8
|
language: wasm/assemblyscript
|
|
7
9
|
entities:
|
|
8
10
|
- ExampleEntity
|
|
9
11
|
receiptHandlers:
|
|
10
12
|
- handler: handleReceipt
|
|
11
|
-
file: ./src
|
|
13
|
+
file: ./src/${strings.kebabCase(contractName)}.ts`
|
|
12
14
|
|
|
13
15
|
module.exports = {
|
|
14
16
|
source,
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const immutable = require('immutable')
|
|
2
|
+
const Scaffold = require('./')
|
|
3
|
+
const Protocol = require('../protocols')
|
|
4
|
+
|
|
5
|
+
const protocol = new Protocol('cosmos')
|
|
6
|
+
|
|
7
|
+
const scaffoldOptions = {
|
|
8
|
+
protocol,
|
|
9
|
+
network: 'cosmoshub-4',
|
|
10
|
+
dataSourceName: 'CosmosHub'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const scaffold = new Scaffold(scaffoldOptions)
|
|
14
|
+
|
|
15
|
+
describe('Cosmos subgraph scaffolding', () => {
|
|
16
|
+
test('Manifest', () => {
|
|
17
|
+
expect(
|
|
18
|
+
scaffold.generateManifest(),
|
|
19
|
+
).toEqual(`\
|
|
20
|
+
specVersion: 0.0.1
|
|
21
|
+
schema:
|
|
22
|
+
file: ./schema.graphql
|
|
23
|
+
dataSources:
|
|
24
|
+
- kind: cosmos
|
|
25
|
+
name: CosmosHub
|
|
26
|
+
network: cosmoshub-4
|
|
27
|
+
source:
|
|
28
|
+
startBlock: 0
|
|
29
|
+
mapping:
|
|
30
|
+
apiVersion: 0.0.5
|
|
31
|
+
language: wasm/assemblyscript
|
|
32
|
+
entities:
|
|
33
|
+
- ExampleEntity
|
|
34
|
+
blockHandlers:
|
|
35
|
+
- handler: handleBlock
|
|
36
|
+
file: ./src/mapping.ts
|
|
37
|
+
`)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('Schema (default)', () => {
|
|
41
|
+
expect(scaffold.generateSchema()).toEqual(`\
|
|
42
|
+
type ExampleEntity @entity {
|
|
43
|
+
id: ID!
|
|
44
|
+
block: Bytes!
|
|
45
|
+
count: BigInt!
|
|
46
|
+
}
|
|
47
|
+
`)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('Mapping (default)', () => {
|
|
51
|
+
expect(scaffold.generateMapping()).toEqual(`\
|
|
52
|
+
import { cosmos, BigInt } from "@graphprotocol/graph-ts"
|
|
53
|
+
import { ExampleEntity } from "../generated/schema"
|
|
54
|
+
|
|
55
|
+
export function handleBlock(block: cosmos.Block): void {
|
|
56
|
+
// Entities can be loaded from the store using a string ID; this ID
|
|
57
|
+
// needs to be unique across all entities of the same type
|
|
58
|
+
let entity = ExampleEntity.load(block.header.hash.toHex())
|
|
59
|
+
|
|
60
|
+
// Entities only exist after they have been saved to the store;
|
|
61
|
+
// \`null\` checks allow to create entities on demand
|
|
62
|
+
if (!entity) {
|
|
63
|
+
entity = new ExampleEntity(block.header.hash.toHex())
|
|
64
|
+
|
|
65
|
+
// Entity fields can be set using simple assignments
|
|
66
|
+
entity.count = BigInt.fromI32(0)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// BigInt and BigDecimal math are supported
|
|
70
|
+
entity.count = entity.count + BigInt.fromI32(1)
|
|
71
|
+
|
|
72
|
+
// Entity fields can be set based on receipt information
|
|
73
|
+
entity.height = block.header.height
|
|
74
|
+
|
|
75
|
+
// Entities can be written to the store with \`.save()\`
|
|
76
|
+
entity.save()
|
|
77
|
+
|
|
78
|
+
// Note: If a handler doesn't require existing field values, it is faster
|
|
79
|
+
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
80
|
+
// \`new Entity(...)\`, set the fields that should be updated and save the
|
|
81
|
+
// entity back to the store. Fields that were not set or unset remain
|
|
82
|
+
// unchanged, allowing for partial updates to be applied.
|
|
83
|
+
}
|
|
84
|
+
`)
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -77,6 +77,7 @@ const scaffoldOptions = {
|
|
|
77
77
|
contract: '0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d',
|
|
78
78
|
network: 'kovan',
|
|
79
79
|
contractName: 'Contract',
|
|
80
|
+
dataSourceName: 'Contract'
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
const scaffold = new Scaffold(scaffoldOptions)
|
|
@@ -116,7 +117,7 @@ dataSources:
|
|
|
116
117
|
handler: handleExampleEvent
|
|
117
118
|
- event: ExampleEvent(bytes32)
|
|
118
119
|
handler: handleExampleEvent1
|
|
119
|
-
file: ./src/
|
|
120
|
+
file: ./src/contract.ts
|
|
120
121
|
`)
|
|
121
122
|
})
|
|
122
123
|
|