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/nervous-garlics-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

show sourcify fetch status
2 changes: 1 addition & 1 deletion packages/cli/src/command-helpers/spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const withSpinner = async (
const spinner = print.spin(text);
try {
const result = await f(spinner);
if (typeof result === 'object') {
if (result && typeof result === 'object') {
const hasError = Object.keys(result).includes('error');
const hasWarning = Object.keys(result).includes('warning');
const hasResult = Object.keys(result).includes('result');
Expand Down
55 changes: 28 additions & 27 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,33 +710,34 @@ async function processInitForm(
return address;
}

const sourcifyContractInfo = await contractService.getFromSourcify(
EthereumABI,
network.id,
address,
);
if (sourcifyContractInfo) {
initStartBlock ??= sourcifyContractInfo.startBlock;
initContractName ??= sourcifyContractInfo.name;
initAbi ??= sourcifyContractInfo.abi;
initDebugger.extend('processInitForm')(
"infoFromSourcify: '%s'/'%s'",
initStartBlock,
initContractName,
);
}

// If ABI is not provided, try to fetch it from Etherscan API
// If ABI is not provided, try to fetch it from Sourcify/Etherscan API
if (protocolInstance.hasABIs() && !initAbi) {
abiFromApi = await retryWithPrompt(() =>
withSpinner(
'Fetching ABI from contract API...',
'Failed to fetch ABI',
'Warning fetching ABI',
() => contractService.getABI(protocolInstance.getABI(), network.id, address),
),
const sourcifyContractInfo = await withSpinner(
'Fetching ABI from Sourcify API...',
'Failed to fetch ABI',
'Warning fetching ABI',
() => contractService.getFromSourcify(protocolInstance.getABI(), network.id, address),
);
initDebugger.extend('processInitForm')("abiFromEtherscan len: '%s'", abiFromApi?.name);
if (sourcifyContractInfo) {
initStartBlock ??= sourcifyContractInfo.startBlock;
initContractName ??= sourcifyContractInfo.name;
abiFromApi ??= sourcifyContractInfo.abi;
initDebugger.extend('processInitForm')(
"infoFromSourcify: '%s'/'%s'",
initStartBlock,
initContractName,
);
} else {
abiFromApi = await retryWithPrompt(() =>
withSpinner(
'Fetching ABI from Contract API...',
'Failed to fetch ABI',
'Warning fetching ABI',
() => contractService.getABI(protocolInstance.getABI(), network.id, address),
),
);
initDebugger.extend('processInitForm')("abiFromEtherscan ABI: '%s'", abiFromApi?.name);
}
} else {
abiFromApi = initAbi;
}
Expand All @@ -745,7 +746,7 @@ async function processInitForm(
if (!initStartBlock) {
startBlock = await retryWithPrompt(() =>
withSpinner(
'Fetching start block from contract API...',
'Fetching start block from Contract API...',
'Failed to fetch start block',
'Warning fetching start block',
() => contractService.getStartBlock(network.id, address),
Expand All @@ -758,7 +759,7 @@ async function processInitForm(
if (!initContractName) {
contractName = await retryWithPrompt(() =>
withSpinner(
'Fetching contract name from contract API...',
'Fetching contract name from Contract API...',
'Failed to fetch contract name',
'Warning fetching contract name',
() => contractService.getContractName(network.id, address),
Expand Down