Skip to content

Commit 032d703

Browse files
feat: ask for SPKG for substreams (#1343)
* upgrade to use gluegun latest and refactor prompts * chore(dependencies): updated changesets for modified dependencies * remove start block, index events as option for substreams * improve directory tree * fix: install cli part of substreams flow * fix: respect --abi init flag * fix: validate loading a localfile * chore(dependencies): updated changesets for modified dependencies * feat: ask for SPKG for substreams --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 7343f50 commit 032d703

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

.changeset/wild-turkeys-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': minor
3+
---
4+
5+
add SPK input for substreams protocol

packages/cli/src/command-helpers/scaffold.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const generateScaffold = async (
5858
contractName = 'Contract',
5959
startBlock,
6060
node,
61+
spkgPath,
6162
}: {
6263
protocolInstance: Protocol;
6364
abi: ABI;
@@ -68,6 +69,7 @@ export const generateScaffold = async (
6869
contractName?: string;
6970
startBlock?: string;
7071
node?: string;
72+
spkgPath?: string;
7173
},
7274
spinner: Spinner,
7375
) => {
@@ -83,6 +85,7 @@ export const generateScaffold = async (
8385
startBlock,
8486
subgraphName,
8587
node,
88+
spkgPath,
8689
});
8790

8891
return scaffold.generate();

packages/cli/src/commands/init.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export default class InitCommand extends Command {
9494
// default: '*Download from Etherscan*',
9595
dependsOn: ['from-contract'],
9696
}),
97+
spkg: Flags.string({
98+
summary: 'Path to the SPKG file',
99+
}),
97100
network: Flags.string({
98101
summary: 'Network the contract is deployed to.',
99102
dependsOn: ['from-contract'],
@@ -121,6 +124,7 @@ export default class InitCommand extends Command {
121124
network,
122125
abi: abiPath,
123126
'start-block': startBlock,
127+
spkg: spkgPath,
124128
},
125129
} = await this.parse(InitCommand);
126130

@@ -234,6 +238,7 @@ export default class InitCommand extends Command {
234238
studio,
235239
product,
236240
startBlock,
241+
spkgPath,
237242
},
238243
{ commands, addContract: false },
239244
);
@@ -258,6 +263,7 @@ export default class InitCommand extends Command {
258263
subgraphName,
259264
contractName,
260265
startBlock,
266+
spkgPath,
261267
});
262268
if (!answers) {
263269
this.exit(1);
@@ -298,6 +304,7 @@ export default class InitCommand extends Command {
298304
studio: answers.studio,
299305
product: answers.product,
300306
startBlock: answers.startBlock,
307+
spkgPath: answers.spkgPath,
301308
},
302309
{ commands, addContract: true },
303310
);
@@ -325,6 +332,7 @@ async function processInitForm(
325332
contractName: initContractName,
326333
startBlock: initStartBlock,
327334
allowSimpleName: initAllowSimpleName,
335+
spkgPath: initSpkgPath,
328336
}: {
329337
protocol?: ProtocolName;
330338
product?: string;
@@ -341,6 +349,7 @@ async function processInitForm(
341349
subgraphName?: string;
342350
contractName?: string;
343351
startBlock?: string;
352+
spkgPath?: string;
344353
},
345354
): Promise<
346355
| {
@@ -356,6 +365,7 @@ async function processInitForm(
356365
contractName: string;
357366
startBlock: string;
358367
fromExample: boolean;
368+
spkgPath: string | undefined;
359369
}
360370
| undefined
361371
> {
@@ -517,6 +527,18 @@ async function processInitForm(
517527
},
518528
]);
519529

530+
const { spkg } = await prompt.ask<{ spkg: string }>([
531+
{
532+
type: 'input',
533+
name: 'spkg',
534+
message: 'SPKG file (path)',
535+
initial: () => initSpkgPath,
536+
skip: () => !isSubstreams || !!initSpkgPath,
537+
validate: value =>
538+
filesystem.exists(initSpkgPath || value) ? true : 'SPKG file does not exist',
539+
},
540+
]);
541+
520542
const { abi: abiFromFile } = await prompt.ask<{ abi: EthereumABI }>([
521543
{
522544
type: 'input',
@@ -622,6 +644,7 @@ async function processInitForm(
622644
contractName,
623645
contract,
624646
indexEvents,
647+
spkgPath: spkg,
625648
};
626649
} catch (e) {
627650
this.error(e, { exit: 1 });
@@ -925,6 +948,7 @@ async function initSubgraphFromContract(
925948
studio,
926949
product,
927950
startBlock,
951+
spkgPath,
928952
}: {
929953
protocolInstance: Protocol;
930954
allowSimpleName: boolean | undefined;
@@ -939,6 +963,7 @@ async function initSubgraphFromContract(
939963
studio: boolean;
940964
product?: string;
941965
startBlock?: string;
966+
spkgPath?: string;
942967
},
943968
{
944969
commands,
@@ -1002,6 +1027,7 @@ async function initSubgraphFromContract(
10021027
contractName,
10031028
startBlock,
10041029
node,
1030+
spkgPath,
10051031
},
10061032
spinner,
10071033
);

packages/cli/src/protocols/substreams/scaffold/manifest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export const source = () => `
1+
export const source = ({ spkgPath }: { spkgPath?: string }) => `
22
package:
33
moduleName: graph_out
4-
file: substreams-eth-block-meta-v0.1.0.spkg`;
4+
file: ${spkgPath || 'substreams-eth-block-meta-v0.1.0.spkg'}`;
55

66
export const mapping = () => `
77
apiVersion: 0.0.5

packages/cli/src/scaffold/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface ScaffoldOptions {
2525
startBlock?: string;
2626
subgraphName?: string;
2727
node?: string;
28+
spkgPath?: string;
2829
}
2930

3031
export default class Scaffold {
@@ -37,6 +38,7 @@ export default class Scaffold {
3738
subgraphName?: string;
3839
node?: string;
3940
startBlock?: string;
41+
spkgPath?: string;
4042

4143
constructor(options: ScaffoldOptions) {
4244
this.protocol = options.protocol;
@@ -48,6 +50,7 @@ export default class Scaffold {
4850
this.subgraphName = options.subgraphName;
4951
this.startBlock = options.startBlock;
5052
this.node = options.node;
53+
this.spkgPath = options.spkgPath;
5154
}
5255

5356
generatePackageJson() {

0 commit comments

Comments
 (0)