Skip to content

Commit 388ee5a

Browse files
graph init: Show Sourcify fetch status (#1967)
* graph init: show sourcify status * handle null on return from the spinner * changeset
1 parent 4e2b689 commit 388ee5a

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

.changeset/nervous-garlics-cover.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': patch
3+
---
4+
5+
show sourcify fetch status

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const withSpinner = async (
3636
const spinner = print.spin(text);
3737
try {
3838
const result = await f(spinner);
39-
if (typeof result === 'object') {
39+
if (result && typeof result === 'object') {
4040
const hasError = Object.keys(result).includes('error');
4141
const hasWarning = Object.keys(result).includes('warning');
4242
const hasResult = Object.keys(result).includes('result');

packages/cli/src/commands/init.ts

+28-27
Original file line numberDiff line numberDiff line change
@@ -710,33 +710,34 @@ async function processInitForm(
710710
return address;
711711
}
712712

713-
const sourcifyContractInfo = await contractService.getFromSourcify(
714-
EthereumABI,
715-
network.id,
716-
address,
717-
);
718-
if (sourcifyContractInfo) {
719-
initStartBlock ??= sourcifyContractInfo.startBlock;
720-
initContractName ??= sourcifyContractInfo.name;
721-
initAbi ??= sourcifyContractInfo.abi;
722-
initDebugger.extend('processInitForm')(
723-
"infoFromSourcify: '%s'/'%s'",
724-
initStartBlock,
725-
initContractName,
726-
);
727-
}
728-
729-
// If ABI is not provided, try to fetch it from Etherscan API
713+
// If ABI is not provided, try to fetch it from Sourcify/Etherscan API
730714
if (protocolInstance.hasABIs() && !initAbi) {
731-
abiFromApi = await retryWithPrompt(() =>
732-
withSpinner(
733-
'Fetching ABI from contract API...',
734-
'Failed to fetch ABI',
735-
'Warning fetching ABI',
736-
() => contractService.getABI(protocolInstance.getABI(), network.id, address),
737-
),
715+
const sourcifyContractInfo = await withSpinner(
716+
'Fetching ABI from Sourcify API...',
717+
'Failed to fetch ABI',
718+
'Warning fetching ABI',
719+
() => contractService.getFromSourcify(protocolInstance.getABI(), network.id, address),
738720
);
739-
initDebugger.extend('processInitForm')("abiFromEtherscan len: '%s'", abiFromApi?.name);
721+
if (sourcifyContractInfo) {
722+
initStartBlock ??= sourcifyContractInfo.startBlock;
723+
initContractName ??= sourcifyContractInfo.name;
724+
abiFromApi ??= sourcifyContractInfo.abi;
725+
initDebugger.extend('processInitForm')(
726+
"infoFromSourcify: '%s'/'%s'",
727+
initStartBlock,
728+
initContractName,
729+
);
730+
} else {
731+
abiFromApi = await retryWithPrompt(() =>
732+
withSpinner(
733+
'Fetching ABI from Contract API...',
734+
'Failed to fetch ABI',
735+
'Warning fetching ABI',
736+
() => contractService.getABI(protocolInstance.getABI(), network.id, address),
737+
),
738+
);
739+
initDebugger.extend('processInitForm')("abiFromEtherscan ABI: '%s'", abiFromApi?.name);
740+
}
740741
} else {
741742
abiFromApi = initAbi;
742743
}
@@ -745,7 +746,7 @@ async function processInitForm(
745746
if (!initStartBlock) {
746747
startBlock = await retryWithPrompt(() =>
747748
withSpinner(
748-
'Fetching start block from contract API...',
749+
'Fetching start block from Contract API...',
749750
'Failed to fetch start block',
750751
'Warning fetching start block',
751752
() => contractService.getStartBlock(network.id, address),
@@ -758,7 +759,7 @@ async function processInitForm(
758759
if (!initContractName) {
759760
contractName = await retryWithPrompt(() =>
760761
withSpinner(
761-
'Fetching contract name from contract API...',
762+
'Fetching contract name from Contract API...',
762763
'Failed to fetch contract name',
763764
'Warning fetching contract name',
764765
() => contractService.getContractName(network.id, address),

0 commit comments

Comments
 (0)