@graphprotocol/graph-cli 0.42.0-rc-20230223152152-ba48e50 → 0.42.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.42.0-rc-20230223152152-ba48e50
3
+ ## 0.42.0
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -8,6 +8,10 @@
8
8
  [`2ebd032`](https://github.com/graphprotocol/graph-tooling/commit/2ebd0326cab00efc9abad7ad4287cee20a8cfea2)
9
9
  Thanks [@incrypto32](https://github.com/incrypto32)! - Add base scan URL
10
10
 
11
+ - [#1068](https://github.com/graphprotocol/graph-tooling/pull/1068)
12
+ [`1e3195d`](https://github.com/graphprotocol/graph-tooling/commit/1e3195d365bd445f8bd6ba3f1c3b66be20510b94)
13
+ Thanks [@incrypto32](https://github.com/incrypto32)! - Add startblock auto fetch for `add` command
14
+
11
15
  - [#1079](https://github.com/graphprotocol/graph-tooling/pull/1079)
12
16
  [`570eb22`](https://github.com/graphprotocol/graph-tooling/commit/570eb225fad705998cca3998879a6a1140a73143)
13
17
  Thanks [@incrypto32](https://github.com/incrypto32)! - Remove optimism-kovan, Add optimism-goerli
@@ -15,9 +15,9 @@ const mapping_1 = require("../scaffold/mapping");
15
15
  const schema_1 = require("../scaffold/schema");
16
16
  const tests_1 = require("../scaffold/tests");
17
17
  const spinner_1 = require("./spinner");
18
- const generateDataSource = async (protocol, contractName, network, contractAddress, abi) => {
18
+ const generateDataSource = async (protocol, contractName, network, contractAddress, abi, startBlock) => {
19
19
  const protocolManifest = protocol.getManifestScaffold();
20
- return immutable_1.Map.of('kind', protocol.name, 'name', contractName, 'network', network, 'source', yaml_1.default.parse(prettier_1.default.format(protocolManifest.source({ contract: contractAddress, contractName }), {
20
+ return immutable_1.Map.of('kind', protocol.name, 'name', contractName, 'network', network, 'source', yaml_1.default.parse(prettier_1.default.format(protocolManifest.source({ contract: contractAddress, contractName, startBlock }), {
21
21
  parser: 'yaml',
22
22
  })), 'mapping', yaml_1.default.parse(prettier_1.default.format(protocolManifest.mapping({ abi, contractName }), {
23
23
  parser: 'yaml',
@@ -40,12 +40,13 @@ const abi_2 = __importDefault(require("../protocols/ethereum/abi"));
40
40
  const subgraph_1 = __importDefault(require("../subgraph"));
41
41
  class AddCommand extends core_1.Command {
42
42
  async run() {
43
- const { args: { address, 'subgraph-manifest': manifestPath }, flags: { abi, 'contract-name': contractName, 'merge-entities': mergeEntities, 'network-file': networksFile, }, } = await this.parse(AddCommand);
43
+ const { args: { address, 'subgraph-manifest': manifestPath }, flags: { abi, 'contract-name': contractName, 'merge-entities': mergeEntities, 'network-file': networksFile, 'start-block': startBlockFlag, }, } = await this.parse(AddCommand);
44
44
  const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath);
45
45
  const protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
46
46
  const manifest = await subgraph_1.default.load(manifestPath, { protocol });
47
47
  const network = manifest.result.getIn(['dataSources', 0, 'network']);
48
48
  const result = manifest.result.asMutable();
49
+ let startBlock = startBlockFlag;
49
50
  const entities = getEntities(manifest);
50
51
  const contractNames = getContractNames(manifest);
51
52
  if (contractNames.includes(contractName)) {
@@ -61,6 +62,13 @@ class AddCommand extends core_1.Command {
61
62
  else {
62
63
  ethabi = await (0, abi_1.loadAbiFromEtherscan)(abi_2.default, network, address);
63
64
  }
65
+ try {
66
+ startBlock || (startBlock = Number(await (0, abi_1.loadStartBlockForContract)(network, address)).toString());
67
+ }
68
+ catch (error) {
69
+ // If we can't get the start block, we'll just leave it out of the manifest
70
+ // TODO: Ask the user for the start block
71
+ }
64
72
  const { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(ethabi, entities, contractName, mergeEntities);
65
73
  ethabi.data = abiData;
66
74
  await (0, scaffold_1.writeABI)(ethabi, contractName);
@@ -68,7 +76,7 @@ class AddCommand extends core_1.Command {
68
76
  await (0, scaffold_1.writeMapping)(ethabi, protocol, contractName, collisionEntities);
69
77
  await (0, scaffold_1.writeTestsFiles)(ethabi, protocol, contractName);
70
78
  const dataSources = result.get('dataSources');
71
- const dataSource = await (0, scaffold_1.generateDataSource)(protocol, contractName, network, address, ethabi);
79
+ const dataSource = await (0, scaffold_1.generateDataSource)(protocol, contractName, network, address, ethabi, startBlock);
72
80
  // Handle the collisions edge case by copying another data source yaml data
73
81
  if (mergeEntities && onlyCollisions) {
74
82
  const firstDataSource = dataSources.get(0);
@@ -113,6 +121,10 @@ AddCommand.flags = {
113
121
  summary: 'Path to the contract ABI.',
114
122
  default: '*Download from Etherscan*',
115
123
  }),
124
+ 'start-block': core_1.Flags.string({
125
+ summary: 'The block number to start indexing events from.',
126
+ default: '*Zero*',
127
+ }),
116
128
  'contract-name': core_1.Flags.string({
117
129
  summary: 'Name of the contract.',
118
130
  default: 'Contract',
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.42.0-rc-20230223152152-ba48e50",
2
+ "version": "0.42.0",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
@@ -24,6 +24,13 @@
24
24
  "multiple": false,
25
25
  "default": "*Download from Etherscan*"
26
26
  },
27
+ "start-block": {
28
+ "name": "start-block",
29
+ "type": "option",
30
+ "summary": "The block number to start indexing events from.",
31
+ "multiple": false,
32
+ "default": "*Zero*"
33
+ },
27
34
  "contract-name": {
28
35
  "name": "contract-name",
29
36
  "type": "option",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.42.0-rc-20230223152152-ba48e50",
3
+ "version": "0.42.0",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {