Skip to content

Commit

Permalink
Fix CLI validation for params fetched from external APIs
Browse files Browse the repository at this point in the history
Specifically for `startBlock` and `contractName`.
  • Loading branch information
0237h committed Nov 19, 2024
1 parent 1c68a6b commit 1a3a638
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
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 @@ async function processInitForm(
| 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 @@ async function processInitForm(
loadStartBlockForContract(network, value),
);
if (startBlock) {
initStartBlock = Number(startBlock).toString();
startBlockFromEtherscan = Number(startBlock).toString();
}
}

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

Expand Down Expand Up @@ -666,13 +668,9 @@ async function processInitForm(
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 @@ async function processInitForm(
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

0 comments on commit 1a3a638

Please sign in to comment.