@graphprotocol/graph-cli 0.37.3 → 0.37.4
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/CHANGELOG.md +8 -0
- package/package.json +5 -1
- package/babel.config.js +0 -3
- package/jest.config.js +0 -175
- package/src/bin.ts +0 -6
- package/src/cli.ts +0 -30
- package/src/codegen/schema.test.ts +0 -460
- package/src/codegen/schema.ts +0 -299
- package/src/codegen/template.ts +0 -45
- package/src/codegen/types/conversions.ts +0 -358
- package/src/codegen/types/index.test.ts +0 -715
- package/src/codegen/types/index.ts +0 -111
- package/src/codegen/typescript.ts +0 -224
- package/src/codegen/util.test.ts +0 -112
- package/src/codegen/util.ts +0 -54
- package/src/command-helpers/abi.ts +0 -99
- package/src/command-helpers/auth.ts +0 -46
- package/src/command-helpers/compiler.ts +0 -60
- package/src/command-helpers/data-sources.ts +0 -36
- package/src/command-helpers/fs.ts +0 -5
- package/src/command-helpers/gluegun.ts +0 -52
- package/src/command-helpers/ipfs-http-client.d.ts +0 -1
- package/src/command-helpers/ipfs.ts +0 -3
- package/src/command-helpers/jsonrpc.ts +0 -22
- package/src/command-helpers/network.test.ts +0 -85
- package/src/command-helpers/network.ts +0 -133
- package/src/command-helpers/node.ts +0 -46
- package/src/command-helpers/scaffold.ts +0 -174
- package/src/command-helpers/spinner.ts +0 -60
- package/src/command-helpers/studio.test.ts +0 -84
- package/src/command-helpers/studio.ts +0 -25
- package/src/command-helpers/subgraph.ts +0 -21
- package/src/command-helpers/version.test.ts +0 -241
- package/src/command-helpers/version.ts +0 -53
- package/src/commands/add.ts +0 -220
- package/src/commands/auth.ts +0 -138
- package/src/commands/binary-install-raw.d.ts +0 -1
- package/src/commands/build.ts +0 -147
- package/src/commands/codegen.ts +0 -123
- package/src/commands/create.ts +0 -109
- package/src/commands/deploy.ts +0 -388
- package/src/commands/init.ts +0 -1060
- package/src/commands/local.ts +0 -539
- package/src/commands/remove.ts +0 -110
- package/src/commands/test.ts +0 -369
- package/src/compiler/asc.ts +0 -77
- package/src/compiler/index.ts +0 -677
- package/src/debug.ts +0 -15
- package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
- package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
- package/src/migrations/spec_version_0_0_2.ts +0 -24
- package/src/migrations/spec_version_0_0_3.ts +0 -29
- package/src/migrations/util/load-manifest.ts +0 -10
- package/src/migrations/util/versions.ts +0 -27
- package/src/migrations.ts +0 -33
- package/src/protocols/arweave/manifest.graphql +0 -57
- package/src/protocols/arweave/scaffold/manifest.ts +0 -14
- package/src/protocols/arweave/scaffold/mapping.ts +0 -49
- package/src/protocols/arweave/subgraph.ts +0 -22
- package/src/protocols/contract.ts +0 -9
- package/src/protocols/cosmos/manifest.graphql +0 -76
- package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
- package/src/protocols/cosmos/scaffold/mapping.ts +0 -35
- package/src/protocols/cosmos/subgraph.ts +0 -27
- package/src/protocols/ethereum/abi.ts +0 -153
- package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
- package/src/protocols/ethereum/codegen/abi.ts +0 -719
- package/src/protocols/ethereum/codegen/template.ts +0 -41
- package/src/protocols/ethereum/contract.ts +0 -24
- package/src/protocols/ethereum/manifest.graphql +0 -94
- package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
- package/src/protocols/ethereum/scaffold/mapping.ts +0 -76
- package/src/protocols/ethereum/subgraph.ts +0 -189
- package/src/protocols/ethereum/type-generator.ts +0 -191
- package/src/protocols/index.ts +0 -287
- package/src/protocols/ipfs/codegen/file_template.ts +0 -43
- package/src/protocols/near/contract.ts +0 -47
- package/src/protocols/near/manifest.graphql +0 -64
- package/src/protocols/near/scaffold/manifest.ts +0 -13
- package/src/protocols/near/scaffold/mapping.ts +0 -35
- package/src/protocols/near/subgraph.ts +0 -22
- package/src/protocols/subgraph.ts +0 -12
- package/src/protocols/substreams/manifest.graphql +0 -45
- package/src/protocols/substreams/scaffold/manifest.ts +0 -8
- package/src/protocols/substreams/subgraph.ts +0 -22
- package/src/scaffold/cosmos.test.ts +0 -83
- package/src/scaffold/ethereum.test.ts +0 -512
- package/src/scaffold/index.ts +0 -172
- package/src/scaffold/mapping.ts +0 -44
- package/src/scaffold/near.test.ts +0 -86
- package/src/scaffold/schema.ts +0 -89
- package/src/scaffold/tests.ts +0 -217
- package/src/schema.ts +0 -26
- package/src/subgraph.ts +0 -302
- package/src/type-generator.ts +0 -266
- package/src/validation/contract.ts +0 -51
- package/src/validation/index.ts +0 -5
- package/src/validation/manifest.ts +0 -360
- package/src/validation/schema.test.ts +0 -38
- package/src/validation/schema.ts +0 -957
- package/src/watcher.ts +0 -96
- package/tests/cli/globalSetup.ts +0 -8
- package/tests/cli/globalTeardown.ts +0 -8
- package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
- package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
- package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract.stderr +0 -16
- package/tests/cli/init/ethereum/from-contract.stdout +0 -12
- package/tests/cli/init/ethereum/from-example.stderr +0 -12
- package/tests/cli/init/ethereum/from-example.stdout +0 -12
- package/tests/cli/init/near/from-contract.stderr +0 -14
- package/tests/cli/init/near/from-contract.stdout +0 -12
- package/tests/cli/init.test.ts +0 -157
- package/tests/cli/spawn-command.d.ts +0 -7
- package/tests/cli/util.ts +0 -132
- package/tests/cli/validation/abi-not-found/Abi.json +0 -7
- package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
- package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
- package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
- package/tests/cli/validation/abi-not-found copy.stderr +0 -13
- package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
- package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
- package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
- package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
- package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
- package/tests/cli/validation/call-function-not-found.stderr +0 -10
- package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
- package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
- package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
- package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
- package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
- package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
- package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-network-names.stderr +0 -10
- package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
- package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
- package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
- package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
- package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
- package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
- package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
- package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
- package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
- package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
- package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
- package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
- package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
- package/tests/cli/validation/duplicate-template-name.stderr +0 -5
- package/tests/cli/validation/entity-field-args/Abi.json +0 -7
- package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
- package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
- package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
- package/tests/cli/validation/entity-field-args.stderr +0 -5
- package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
- package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
- package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
- package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
- package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
- package/tests/cli/validation/event-not-found/Abi.json +0 -7
- package/tests/cli/validation/event-not-found/mapping.ts +0 -0
- package/tests/cli/validation/event-not-found/schema.graphql +0 -3
- package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
- package/tests/cli/validation/event-not-found.stderr +0 -12
- package/tests/cli/validation/example-values-found/Abi.json +0 -7
- package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
- package/tests/cli/validation/example-values-found/mapping.ts +0 -0
- package/tests/cli/validation/example-values-found/schema.graphql +0 -3
- package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
- package/tests/cli/validation/example-values-found.stderr +0 -34
- package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
- package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
- package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
- package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-abis.stderr +0 -5
- package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
- package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
- package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
- package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
- package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
- package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
- package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
- package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
- package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
- package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
- package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
- package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
- package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
- package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
- package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
- package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
- package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
- package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
- package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
- package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
- package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
- package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
- package/tests/cli/validation/invalid-manifest.stderr +0 -28
- package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
- package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
- package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
- package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
- package/tests/cli/validation/missing-entity-id.stderr +0 -5
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
- package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
- package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
- package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
- package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
- package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
- package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
- package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
- package/tests/cli/validation/no-network-names/Abi.json +0 -7
- package/tests/cli/validation/no-network-names/mapping.ts +0 -0
- package/tests/cli/validation/no-network-names/schema.graphql +0 -3
- package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
- package/tests/cli/validation/no-network-names.stderr +0 -34
- package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
- package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
- package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
- package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
- package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
- package/tests/cli/validation.test.ts +0 -226
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -19
package/src/protocols/index.ts
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import debug from '../debug';
|
|
3
|
-
import Subgraph from '../subgraph';
|
|
4
|
-
import * as ArweaveManifestScaffold from './arweave/scaffold/manifest';
|
|
5
|
-
import * as ArweaveMappingScaffold from './arweave/scaffold/mapping';
|
|
6
|
-
import ArweaveSubgraph from './arweave/subgraph';
|
|
7
|
-
import { ContractCtor } from './contract';
|
|
8
|
-
import * as CosmosManifestScaffold from './cosmos/scaffold/manifest';
|
|
9
|
-
import * as CosmosMappingScaffold from './cosmos/scaffold/mapping';
|
|
10
|
-
import CosmosSubgraph from './cosmos/subgraph';
|
|
11
|
-
import EthereumABI from './ethereum/abi';
|
|
12
|
-
import EthereumTemplateCodeGen from './ethereum/codegen/template';
|
|
13
|
-
import EthereumContract from './ethereum/contract';
|
|
14
|
-
import * as EthereumManifestScaffold from './ethereum/scaffold/manifest';
|
|
15
|
-
import * as EthereumMappingScaffold from './ethereum/scaffold/mapping';
|
|
16
|
-
import EthereumSubgraph from './ethereum/subgraph';
|
|
17
|
-
import EthereumTypeGenerator from './ethereum/type-generator';
|
|
18
|
-
import NearContract from './near/contract';
|
|
19
|
-
import * as NearManifestScaffold from './near/scaffold/manifest';
|
|
20
|
-
import * as NearMappingScaffold from './near/scaffold/mapping';
|
|
21
|
-
import NearSubgraph from './near/subgraph';
|
|
22
|
-
import { SubgraphOptions } from './subgraph';
|
|
23
|
-
import * as SubstreamsManifestScaffold from './substreams/scaffold/manifest';
|
|
24
|
-
import SubstreamsSubgraph from './substreams/subgraph';
|
|
25
|
-
|
|
26
|
-
const protocolDebug = debug('graph-cli:protocol');
|
|
27
|
-
|
|
28
|
-
export default class Protocol {
|
|
29
|
-
static fromDataSources(dataSourcesAndTemplates: any) {
|
|
30
|
-
const firstDataSourceKind = dataSourcesAndTemplates[0].kind;
|
|
31
|
-
return new Protocol(firstDataSourceKind);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
name: ProtocolName;
|
|
35
|
-
|
|
36
|
-
// TODO: should assert non null? see the constructor switch default case comment
|
|
37
|
-
config!: ProtocolConfig;
|
|
38
|
-
|
|
39
|
-
constructor(name: ProtocolName) {
|
|
40
|
-
this.name = Protocol.normalizeName(name)!;
|
|
41
|
-
|
|
42
|
-
switch (this.name) {
|
|
43
|
-
case 'arweave':
|
|
44
|
-
this.config = arweaveProtocol;
|
|
45
|
-
break;
|
|
46
|
-
case 'cosmos':
|
|
47
|
-
this.config = cosmosProtocol;
|
|
48
|
-
break;
|
|
49
|
-
case 'ethereum':
|
|
50
|
-
this.config = ethereumProtocol;
|
|
51
|
-
break;
|
|
52
|
-
case 'near':
|
|
53
|
-
this.config = nearProtocol;
|
|
54
|
-
break;
|
|
55
|
-
case 'substreams':
|
|
56
|
-
this.config = substreamsProtocol;
|
|
57
|
-
break;
|
|
58
|
-
default:
|
|
59
|
-
// Do not throw when undefined, a better error message is printed after the constructor
|
|
60
|
-
// when validating the Subgraph itself
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
static availableProtocols() {
|
|
65
|
-
return immutable.fromJS({
|
|
66
|
-
// `ethereum/contract` is kept for backwards compatibility.
|
|
67
|
-
// New networks (or protocol perhaps) shouldn't have the `/contract` anymore (unless a new case makes use of it).
|
|
68
|
-
arweave: ['arweave'],
|
|
69
|
-
ethereum: ['ethereum', 'ethereum/contract'],
|
|
70
|
-
near: ['near'],
|
|
71
|
-
cosmos: ['cosmos'],
|
|
72
|
-
substreams: ['substreams'],
|
|
73
|
-
}) as immutable.Collection<ProtocolName, string[]>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
static availableNetworks() {
|
|
77
|
-
let networks = immutable.fromJS({
|
|
78
|
-
arweave: ['arweave-mainnet'],
|
|
79
|
-
ethereum: [
|
|
80
|
-
'mainnet',
|
|
81
|
-
'rinkeby',
|
|
82
|
-
'goerli',
|
|
83
|
-
'poa-core',
|
|
84
|
-
'poa-sokol',
|
|
85
|
-
'gnosis',
|
|
86
|
-
'matic',
|
|
87
|
-
'mumbai',
|
|
88
|
-
'fantom',
|
|
89
|
-
'fantom-testnet',
|
|
90
|
-
'bsc',
|
|
91
|
-
'chapel',
|
|
92
|
-
'clover',
|
|
93
|
-
'avalanche',
|
|
94
|
-
'fuji',
|
|
95
|
-
'celo',
|
|
96
|
-
'celo-alfajores',
|
|
97
|
-
'fuse',
|
|
98
|
-
'moonbeam',
|
|
99
|
-
'moonriver',
|
|
100
|
-
'mbase',
|
|
101
|
-
'arbitrum-one',
|
|
102
|
-
'arbitrum-rinkeby',
|
|
103
|
-
'optimism',
|
|
104
|
-
'optimism-kovan',
|
|
105
|
-
'aurora',
|
|
106
|
-
'aurora-testnet',
|
|
107
|
-
],
|
|
108
|
-
near: ['near-mainnet', 'near-testnet'],
|
|
109
|
-
cosmos: [
|
|
110
|
-
'cosmoshub-4',
|
|
111
|
-
'theta-testnet-001', // CosmosHub testnet
|
|
112
|
-
'osmosis-1',
|
|
113
|
-
'osmo-test-4', // Osmosis testnet
|
|
114
|
-
'juno-1',
|
|
115
|
-
'uni-3', // Juno testnet
|
|
116
|
-
],
|
|
117
|
-
}) as immutable.Map<'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams', string[]>;
|
|
118
|
-
|
|
119
|
-
const allNetworks: string[] = [];
|
|
120
|
-
networks.forEach(value => {
|
|
121
|
-
allNetworks.push(...value);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
networks = networks.set('substreams', allNetworks);
|
|
125
|
-
|
|
126
|
-
return networks;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
static normalizeName(name: ProtocolName) {
|
|
130
|
-
return Protocol.availableProtocols().findKey(possibleNames => {
|
|
131
|
-
return possibleNames.includes(name);
|
|
132
|
-
})!;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
displayName() {
|
|
136
|
-
return this.config?.displayName;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Receives a data source kind, and checks if it's valid
|
|
140
|
-
// for the given protocol instance (this).
|
|
141
|
-
isValidKindName(kind: string) {
|
|
142
|
-
return Protocol.availableProtocols().get(this.name, immutable.List()).includes(kind);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
hasABIs() {
|
|
146
|
-
return this.config.abi != null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
hasContract() {
|
|
150
|
-
return this.config.contract != null;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
hasEvents() {
|
|
154
|
-
// A problem with hasEvents usage in the codebase is that it's almost every where
|
|
155
|
-
// where used, the ABI data is actually use after the conditional, so it seems
|
|
156
|
-
// both concept are related. So internally, we map to this condition.
|
|
157
|
-
return this.hasABIs();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
hasTemplates() {
|
|
161
|
-
return this.config.getTemplateCodeGen != null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
hasDataSourceMappingFile() {
|
|
165
|
-
return this.getMappingScaffold() != null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
getTypeGenerator(options: any) {
|
|
169
|
-
if (this.config == null || this.config.getTypeGenerator == null) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return this.config.getTypeGenerator(options);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
getTemplateCodeGen(template: any) {
|
|
177
|
-
if (!this.hasTemplates()) {
|
|
178
|
-
throw new Error(`Template data sources with kind '${this.name}' are not supported yet`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return this.config.getTemplateCodeGen?.(template);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
getABI() {
|
|
185
|
-
return this.config.abi;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
getSubgraph(options: SubgraphOptions) {
|
|
189
|
-
return this.config.getSubgraph({ ...options, protocol: this });
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
getContract() {
|
|
193
|
-
return this.config.contract;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
getManifestScaffold() {
|
|
197
|
-
return this.config.manifestScaffold;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
getMappingScaffold() {
|
|
201
|
-
return this.config.mappingScaffold;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams';
|
|
206
|
-
|
|
207
|
-
export interface ProtocolConfig {
|
|
208
|
-
displayName: string;
|
|
209
|
-
abi?: any;
|
|
210
|
-
contract?: ContractCtor;
|
|
211
|
-
getTemplateCodeGen?: (template: any) => any;
|
|
212
|
-
getTypeGenerator?: (options: any) => any;
|
|
213
|
-
getSubgraph(options: SubgraphOptions): Subgraph;
|
|
214
|
-
manifestScaffold: any;
|
|
215
|
-
mappingScaffold: any;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const arweaveProtocol: ProtocolConfig = {
|
|
219
|
-
displayName: 'Arweave',
|
|
220
|
-
abi: undefined,
|
|
221
|
-
contract: undefined,
|
|
222
|
-
getTemplateCodeGen: undefined,
|
|
223
|
-
getTypeGenerator: undefined,
|
|
224
|
-
getSubgraph(options) {
|
|
225
|
-
return new ArweaveSubgraph(options);
|
|
226
|
-
},
|
|
227
|
-
manifestScaffold: ArweaveManifestScaffold,
|
|
228
|
-
mappingScaffold: ArweaveMappingScaffold,
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const cosmosProtocol: ProtocolConfig = {
|
|
232
|
-
displayName: 'Cosmos',
|
|
233
|
-
abi: undefined,
|
|
234
|
-
contract: undefined,
|
|
235
|
-
getTemplateCodeGen: undefined,
|
|
236
|
-
getTypeGenerator: undefined,
|
|
237
|
-
getSubgraph(options) {
|
|
238
|
-
return new CosmosSubgraph(options);
|
|
239
|
-
},
|
|
240
|
-
manifestScaffold: CosmosManifestScaffold,
|
|
241
|
-
mappingScaffold: CosmosMappingScaffold,
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
const ethereumProtocol: ProtocolConfig = {
|
|
245
|
-
displayName: 'Ethereum',
|
|
246
|
-
abi: EthereumABI,
|
|
247
|
-
contract: EthereumContract,
|
|
248
|
-
getTemplateCodeGen(template) {
|
|
249
|
-
return new EthereumTemplateCodeGen(template);
|
|
250
|
-
},
|
|
251
|
-
getTypeGenerator(options) {
|
|
252
|
-
return new EthereumTypeGenerator(options);
|
|
253
|
-
},
|
|
254
|
-
getSubgraph(options) {
|
|
255
|
-
return new EthereumSubgraph(options);
|
|
256
|
-
},
|
|
257
|
-
manifestScaffold: EthereumManifestScaffold,
|
|
258
|
-
mappingScaffold: EthereumMappingScaffold,
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const nearProtocol: ProtocolConfig = {
|
|
262
|
-
displayName: 'NEAR',
|
|
263
|
-
abi: undefined,
|
|
264
|
-
contract: NearContract,
|
|
265
|
-
getTypeGenerator: undefined,
|
|
266
|
-
getTemplateCodeGen: undefined,
|
|
267
|
-
getSubgraph(options) {
|
|
268
|
-
return new NearSubgraph(options);
|
|
269
|
-
},
|
|
270
|
-
manifestScaffold: NearManifestScaffold,
|
|
271
|
-
mappingScaffold: NearMappingScaffold,
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const substreamsProtocol: ProtocolConfig = {
|
|
275
|
-
displayName: 'Substreams',
|
|
276
|
-
abi: undefined,
|
|
277
|
-
contract: undefined,
|
|
278
|
-
getTypeGenerator: undefined,
|
|
279
|
-
getTemplateCodeGen: undefined,
|
|
280
|
-
getSubgraph(options) {
|
|
281
|
-
return new SubstreamsSubgraph(options);
|
|
282
|
-
},
|
|
283
|
-
manifestScaffold: SubstreamsManifestScaffold,
|
|
284
|
-
mappingScaffold: undefined,
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
protocolDebug('Available networks %M', Protocol.availableNetworks());
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
import immutable from 'immutable';
|
|
4
|
-
import * as tsCodegen from '../../../codegen/typescript';
|
|
5
|
-
|
|
6
|
-
export default class IpfsFileTemplateCodeGen {
|
|
7
|
-
constructor(private template: immutable.Map<any, any>) {
|
|
8
|
-
this.template = template;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
generateModuleImports() {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
generateCreateMethod() {
|
|
16
|
-
const name = this.template.get('name');
|
|
17
|
-
|
|
18
|
-
return tsCodegen.staticMethod(
|
|
19
|
-
'create',
|
|
20
|
-
[tsCodegen.param('cid', tsCodegen.namedType('string'))],
|
|
21
|
-
tsCodegen.namedType('void'),
|
|
22
|
-
`
|
|
23
|
-
DataSourceTemplate.create('${name}', [cid])
|
|
24
|
-
`,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
generateCreateWithContextMethod() {
|
|
29
|
-
const name = this.template.get('name');
|
|
30
|
-
|
|
31
|
-
return tsCodegen.staticMethod(
|
|
32
|
-
'createWithContext',
|
|
33
|
-
[
|
|
34
|
-
tsCodegen.param('cid', tsCodegen.namedType('string')),
|
|
35
|
-
tsCodegen.param('context', tsCodegen.namedType('DataSourceContext')),
|
|
36
|
-
],
|
|
37
|
-
tsCodegen.namedType('void'),
|
|
38
|
-
`
|
|
39
|
-
DataSourceTemplate.createWithContext('${name}', [cid], context)
|
|
40
|
-
`,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Contract } from '../contract';
|
|
2
|
-
|
|
3
|
-
const MINIMUM_ACCOUNT_ID_LENGTH = 2 as const;
|
|
4
|
-
const MAXIMUM_ACCOUNT_ID_LENGTH = 64 as const;
|
|
5
|
-
|
|
6
|
-
const RULES_URL = 'https://docs.near.org/docs/concepts/account#account-id-rules' as const;
|
|
7
|
-
|
|
8
|
-
export default class NearContract implements Contract {
|
|
9
|
-
static identifierName() {
|
|
10
|
-
return 'account';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
constructor(private account: string) {
|
|
14
|
-
this.account = account;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private validateLength(value: string) {
|
|
18
|
-
return value.length >= MINIMUM_ACCOUNT_ID_LENGTH && value.length <= MAXIMUM_ACCOUNT_ID_LENGTH;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private validateFormat(value: string) {
|
|
22
|
-
const pattern = /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/;
|
|
23
|
-
|
|
24
|
-
return pattern.test(value);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
validate() {
|
|
28
|
-
if (!this.validateLength(this.account)) {
|
|
29
|
-
return {
|
|
30
|
-
valid: false,
|
|
31
|
-
error: `Account must be between '${MINIMUM_ACCOUNT_ID_LENGTH}' and '${MAXIMUM_ACCOUNT_ID_LENGTH}' characters, see ${RULES_URL}`,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!this.validateFormat(this.account)) {
|
|
36
|
-
return {
|
|
37
|
-
valid: false,
|
|
38
|
-
error: `Account must conform to the rules on ${RULES_URL}`,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
valid: true,
|
|
44
|
-
error: null,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
features: [String!]
|
|
14
|
-
schema: Schema!
|
|
15
|
-
description: String
|
|
16
|
-
repository: String
|
|
17
|
-
graft: Graft
|
|
18
|
-
dataSources: [DataSource!]!
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type Schema {
|
|
22
|
-
file: File!
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type DataSource {
|
|
26
|
-
kind: String!
|
|
27
|
-
name: String!
|
|
28
|
-
network: String
|
|
29
|
-
source: ContractSource!
|
|
30
|
-
mapping: ContractMapping!
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type ContractSource {
|
|
34
|
-
account: String
|
|
35
|
-
startBlock: BigInt
|
|
36
|
-
accounts: PartialAccount
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type PartialAccount {
|
|
40
|
-
prefixes: [String!]
|
|
41
|
-
suffixes: [String!]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type ContractMapping {
|
|
45
|
-
apiVersion: String!
|
|
46
|
-
language: String!
|
|
47
|
-
file: File!
|
|
48
|
-
entities: [String!]!
|
|
49
|
-
blockHandlers: [BlockHandler!]
|
|
50
|
-
receiptHandlers: [ReceiptHandler!]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
type BlockHandler {
|
|
54
|
-
handler: String!
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
type ReceiptHandler {
|
|
58
|
-
handler: String!
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type Graft {
|
|
62
|
-
base: String!
|
|
63
|
-
block: BigInt!
|
|
64
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { strings } from 'gluegun';
|
|
2
|
-
|
|
3
|
-
export const source = ({ contract }: { contract: string }) => `
|
|
4
|
-
account: '${contract}'`;
|
|
5
|
-
|
|
6
|
-
export const mapping = ({ contractName }: { contractName: string }) => `
|
|
7
|
-
apiVersion: 0.0.5
|
|
8
|
-
language: wasm/assemblyscript
|
|
9
|
-
entities:
|
|
10
|
-
- ExampleEntity
|
|
11
|
-
receiptHandlers:
|
|
12
|
-
- handler: handleReceipt
|
|
13
|
-
file: ./src/${strings.kebabCase(contractName)}.ts`;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export const generatePlaceholderHandlers = () =>
|
|
2
|
-
`
|
|
3
|
-
import { near, BigInt } from '@graphprotocol/graph-ts'
|
|
4
|
-
import { ExampleEntity } from '../generated/schema'
|
|
5
|
-
|
|
6
|
-
export function handleReceipt(receiptWithOutcome: near.ReceiptWithOutcome): 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(receiptWithOutcome.receipt.id.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(receiptWithOutcome.receipt.id.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.block = receiptWithOutcome.block.header.hash
|
|
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
|
-
`;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import { Subgraph, SubgraphOptions } from '../subgraph';
|
|
3
|
-
|
|
4
|
-
export default class NearSubgraph implements Subgraph {
|
|
5
|
-
public manifest: SubgraphOptions['manifest'];
|
|
6
|
-
public resolveFile: SubgraphOptions['resolveFile'];
|
|
7
|
-
public protocol: SubgraphOptions['protocol'];
|
|
8
|
-
|
|
9
|
-
constructor(options: SubgraphOptions) {
|
|
10
|
-
this.manifest = options.manifest;
|
|
11
|
-
this.resolveFile = options.resolveFile;
|
|
12
|
-
this.protocol = options.protocol;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
validateManifest() {
|
|
16
|
-
return immutable.List();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
handlerTypes() {
|
|
20
|
-
return immutable.List(['blockHandlers', 'receiptHandlers']);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
|
|
3
|
-
export interface SubgraphOptions {
|
|
4
|
-
manifest?: any;
|
|
5
|
-
resolveFile: (path: string) => string;
|
|
6
|
-
protocol?: any;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface Subgraph extends SubgraphOptions {
|
|
10
|
-
validateManifest(): immutable.List<any>;
|
|
11
|
-
handlerTypes(): immutable.List<any>;
|
|
12
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
features: [String!]
|
|
14
|
-
schema: Schema!
|
|
15
|
-
description: String
|
|
16
|
-
repository: String
|
|
17
|
-
graft: Graft
|
|
18
|
-
dataSources: [DataSource!]!
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type Schema {
|
|
22
|
-
file: File!
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type DataSource {
|
|
26
|
-
kind: String!
|
|
27
|
-
name: String!
|
|
28
|
-
network: String
|
|
29
|
-
source: SubstreamsSource!
|
|
30
|
-
mapping: SubstreamMapping!
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type SubstreamsSource {
|
|
34
|
-
package: SubstreamsPackage!
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type SubstreamsPackage {
|
|
38
|
-
moduleName: String!
|
|
39
|
-
file: String!
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type SubstreamMapping {
|
|
43
|
-
apiVersion: String!
|
|
44
|
-
kind: String!
|
|
45
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import { Subgraph, SubgraphOptions } from '../subgraph';
|
|
3
|
-
|
|
4
|
-
export default class SubstreamsSubgraph implements Subgraph {
|
|
5
|
-
public manifest: SubgraphOptions['manifest'];
|
|
6
|
-
public resolveFile: SubgraphOptions['resolveFile'];
|
|
7
|
-
public protocol: SubgraphOptions['protocol'];
|
|
8
|
-
|
|
9
|
-
constructor(options: SubgraphOptions) {
|
|
10
|
-
this.manifest = options.manifest;
|
|
11
|
-
this.resolveFile = options.resolveFile;
|
|
12
|
-
this.protocol = options.protocol;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
validateManifest() {
|
|
16
|
-
return immutable.List();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
handlerTypes() {
|
|
20
|
-
return immutable.List([]);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import Protocol from '../protocols';
|
|
2
|
-
import Scaffold from './index';
|
|
3
|
-
|
|
4
|
-
const protocol = new Protocol('cosmos');
|
|
5
|
-
|
|
6
|
-
const scaffoldOptions = {
|
|
7
|
-
protocol,
|
|
8
|
-
network: 'cosmoshub-4',
|
|
9
|
-
contractName: 'CosmosHub',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const scaffold = new Scaffold(scaffoldOptions);
|
|
13
|
-
|
|
14
|
-
describe('Cosmos subgraph scaffolding', () => {
|
|
15
|
-
test('Manifest', () => {
|
|
16
|
-
expect(scaffold.generateManifest()).toEqual(`\
|
|
17
|
-
specVersion: 0.0.5
|
|
18
|
-
schema:
|
|
19
|
-
file: ./schema.graphql
|
|
20
|
-
dataSources:
|
|
21
|
-
- kind: cosmos
|
|
22
|
-
name: CosmosHub
|
|
23
|
-
network: cosmoshub-4
|
|
24
|
-
source:
|
|
25
|
-
startBlock: 0
|
|
26
|
-
mapping:
|
|
27
|
-
apiVersion: 0.0.5
|
|
28
|
-
language: wasm/assemblyscript
|
|
29
|
-
entities:
|
|
30
|
-
- ExampleEntity
|
|
31
|
-
blockHandlers:
|
|
32
|
-
- handler: handleBlock
|
|
33
|
-
file: ./src/contract.ts
|
|
34
|
-
`);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('Schema (default)', () => {
|
|
38
|
-
expect(scaffold.generateSchema()).toEqual(`\
|
|
39
|
-
type ExampleEntity @entity {
|
|
40
|
-
id: ID!
|
|
41
|
-
block: Bytes!
|
|
42
|
-
count: BigInt!
|
|
43
|
-
}
|
|
44
|
-
`);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('Mapping (default)', () => {
|
|
48
|
-
expect(scaffold.generateMapping()).toEqual(`\
|
|
49
|
-
import { cosmos, BigInt } from "@graphprotocol/graph-ts"
|
|
50
|
-
import { ExampleEntity } from "../generated/schema"
|
|
51
|
-
|
|
52
|
-
export function handleBlock(block: cosmos.Block): void {
|
|
53
|
-
// Entities can be loaded from the store using a string ID; this ID
|
|
54
|
-
// needs to be unique across all entities of the same type
|
|
55
|
-
let entity = ExampleEntity.load(block.header.hash.toHex())
|
|
56
|
-
|
|
57
|
-
// Entities only exist after they have been saved to the store;
|
|
58
|
-
// \`null\` checks allow to create entities on demand
|
|
59
|
-
if (!entity) {
|
|
60
|
-
entity = new ExampleEntity(block.header.hash.toHex())
|
|
61
|
-
|
|
62
|
-
// Entity fields can be set using simple assignments
|
|
63
|
-
entity.count = BigInt.fromI32(0)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// BigInt and BigDecimal math are supported
|
|
67
|
-
entity.count = entity.count + BigInt.fromI32(1)
|
|
68
|
-
|
|
69
|
-
// Entity fields can be set based on receipt information
|
|
70
|
-
entity.height = block.header.height
|
|
71
|
-
|
|
72
|
-
// Entities can be written to the store with \`.save()\`
|
|
73
|
-
entity.save()
|
|
74
|
-
|
|
75
|
-
// Note: If a handler doesn't require existing field values, it is faster
|
|
76
|
-
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
77
|
-
// \`new Entity(...)\`, set the fields that should be updated and save the
|
|
78
|
-
// entity back to the store. Fields that were not set or unset remain
|
|
79
|
-
// unchanged, allowing for partial updates to be applied.
|
|
80
|
-
}
|
|
81
|
-
`);
|
|
82
|
-
});
|
|
83
|
-
});
|