Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix graph add Etherscan lookups when using localhost network #1751

Merged
merged 1 commit into from
Oct 31, 2024
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/cold-snails-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

Using `graph add` with `localhost` network now prompts the user for input
41 changes: 40 additions & 1 deletion packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export default class AddCommand extends Command {
const manifest = await Subgraph.load(manifestPath, { protocol });
const network = manifest.result.getIn(['dataSources', 0, 'network']) as any;
const result = manifest.result.asMutable();
const isLocalHost = network === 'localhost'; // This flag prevent Etherscan lookups in case the network selected is `localhost`

if (isLocalHost) this.warn('`localhost` network detected, prompting user for inputs');

let startBlock = startBlockFlag;
let contractName = contractNameFlag;
Expand All @@ -96,10 +99,44 @@ export default class AddCommand extends Command {
} else if (network === 'poa-core') {
ethabi = await loadAbiFromBlockScout(EthereumABI, network, address);
} else {
ethabi = await loadAbiFromEtherscan(EthereumABI, network, address);
try {
if (isLocalHost) throw Error; // Triggers user prompting without waiting for Etherscan lookup to fail

ethabi = await loadAbiFromEtherscan(EthereumABI, network, address);
} catch (error) {
// we cannot ask user to do prompt in test environment
if (process.env.NODE_ENV !== 'test') {
const { abi: abiFromFile } = await prompt.ask<{ abi: EthereumABI }>([
{
type: 'input',
name: 'abi',
message: 'ABI file (path)',
initial: ethabi,
validate: async (value: string) => {
try {
EthereumABI.load(contractName, value);
return true;
} catch (e) {
this.error(e.message);
}
},
result: async (value: string) => {
try {
return EthereumABI.load(contractName, value);
} catch (e) {
return e.message;
}
},
},
]);
ethabi = abiFromFile;
}
}
}

try {
if (isLocalHost) throw Error; // Triggers user prompting without waiting for Etherscan lookup to fail

startBlock ||= Number(await loadStartBlockForContract(network, address)).toString();
} catch (error) {
// we cannot ask user to do prompt in test environment
Expand All @@ -122,6 +159,8 @@ export default class AddCommand extends Command {
}

try {
if (isLocalHost) throw Error; // Triggers user prompting without waiting for Etherscan lookup to fail

contractName = await loadContractNameForAddress(network, address);
} catch (error) {
// not asking user to do prompt in test environment
Expand Down
Loading