Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-moose-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

Fix CLI validation for `startBlock` and `contractName` fetched from external APIs
18 changes: 6 additions & 12 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@
| undefined
> {
let abiFromEtherscan: EthereumABI | undefined = undefined;
let startBlockFromEtherscan: string | undefined = undefined;
let contractNameFromEtherscan: string | undefined = undefined;

try {
const { protocol } = await prompt.ask<{ protocol: ProtocolName }>({
Expand Down Expand Up @@ -586,7 +588,7 @@
loadStartBlockForContract(network, value),
);
if (startBlock) {
initStartBlock = Number(startBlock).toString();
startBlockFromEtherscan = Number(startBlock).toString();
}
}

Expand All @@ -597,7 +599,7 @@
loadContractNameForAddress(network, value),
);
if (contractName) {
initContractName = contractName;
contractNameFromEtherscan = contractName;
}
}

Expand Down Expand Up @@ -666,13 +668,9 @@
type: 'input',
name: 'startBlock',
message: 'Start Block',
initial: initStartBlock || '0',
initial: initStartBlock || startBlockFromEtherscan || '0',
skip: () => initFromExample !== undefined || isSubstreams,
validate: value => parseInt(value) >= 0,
result(value) {
if (initStartBlock) return initStartBlock;
return value;
},
},
]);

Expand All @@ -681,13 +679,9 @@
type: 'input',
name: 'contractName',
message: 'Contract Name',
initial: initContractName || 'Contract' || isSubstreams,
initial: initContractName || contractNameFromEtherscan || 'Contract' || isSubstreams,
skip: () => initFromExample !== undefined || !protocolInstance.hasContract(),
validate: value => value && value.length > 0,
result(value) {
if (initContractName) return initContractName;
return value;
},
},
]);

Expand Down Expand Up @@ -1089,7 +1083,7 @@
}

if (protocolInstance.hasContract()) {
const identifierName = protocolInstance.getContract()!.identifierName();

Check warning on line 1086 in packages/cli/src/commands/init.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion
const networkConf = await initNetworksConfig(directory, identifierName);
if (networkConf !== true) {
process.exitCode = 1;
Expand Down Expand Up @@ -1152,7 +1146,7 @@
const addContractConfirmation = addContractAnswer.toLowerCase() === 'y';

if (addContractConfirmation) {
const ProtocolContract = protocolInstance.getContract()!;

Check warning on line 1149 in packages/cli/src/commands/init.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion

let contract = '';
for (;;) {
Expand Down
Loading