Skip to content

Commit 78aaa25

Browse files
committed
fix near handling
1 parent 8e88023 commit 78aaa25

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ContractService {
1212

1313
private async fetchFromEtherscan(url: string): Promise<any | null> {
1414
const result = await fetch(url).catch(_error => {
15-
throw new Error(`Etherscan API is unreachable`);
15+
throw new Error(`Contract API is unreachable`);
1616
});
1717
let json: any = {};
1818

@@ -25,7 +25,7 @@ export class ContractService {
2525
}
2626

2727
logger(
28-
'Failed to fetch from etherscan: [%s] %s (%s)\n%O',
28+
'Failed to fetch from contract API: [%s] %s (%s)\n%O',
2929
result.status,
3030
result.statusText,
3131
result.url,
@@ -75,12 +75,12 @@ export class ContractService {
7575

7676
let errors: string[] = [];
7777
return await withSpinner(
78-
`Fetching ABI from Etherscan`,
79-
`Failed to fetch ABI from Etherscan`,
80-
`Warnings while fetching ABI from Etherscan`,
78+
`Fetching ABI from contract API`,
79+
`Failed to fetch ABI from contract API`,
80+
`Warnings while fetching ABI from contract API`,
8181
async () => {
8282
if (!urls.length) {
83-
throw new Error(`No Etherscan API available`);
83+
throw new Error(`No contract API available for ${networkId} in the registry`);
8484
}
8585
for (const url of urls) {
8686
try {
@@ -107,12 +107,12 @@ export class ContractService {
107107
const urls = this.getEtherscanUrls(networkId);
108108

109109
return await withSpinner(
110-
`Fetching Start Block`,
111-
`Failed to fetch Start Block`,
112-
`Warnings while fetching deploy contract transaction from Etherscan`,
110+
`Fetching start block`,
111+
`Failed to fetch start block`,
112+
`Warnings while fetching deploy contract transaction from contract API`,
113113
async () => {
114114
if (!urls.length) {
115-
throw new Error(`No Etherscan API available`);
115+
throw new Error(`No contract API available for ${networkId} in the registry`);
116116
}
117117
for (const url of urls) {
118118
try {
@@ -146,12 +146,12 @@ export class ContractService {
146146
const urls = this.getEtherscanUrls(networkId);
147147

148148
return await withSpinner(
149-
`Fetching Contract Name`,
150-
`Failed to fetch Contract Name`,
151-
`Warnings while fetching contract name from Etherscan`,
149+
`Fetching contract name`,
150+
`Failed to fetch contract name`,
151+
`Warnings while fetching contract name from contract API`,
152152
async () => {
153153
if (!urls.length) {
154-
throw new Error(`No Etherscan API available`);
154+
throw new Error(`No contract API available for ${networkId} in the registry`);
155155
}
156156
for (const url of urls) {
157157
try {
@@ -179,7 +179,7 @@ export class ContractService {
179179
private async fetchTransactionByHash(networkId: string, txHash: string) {
180180
const urls = this.getRpcUrls(networkId);
181181
if (!urls.length) {
182-
throw new Error(`No JSON-RPC available`);
182+
throw new Error(`No JSON-RPC available for ${networkId} in the registry`);
183183
}
184184
for (const url of urls) {
185185
try {

packages/cli/src/commands/init.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,6 @@ async function processInitForm(
496496
if (name === 'cosmos') {
497497
return 'Cosmos chains only supported via substreams';
498498
}
499-
if (name === 'near') {
500-
return 'Near chains only supported via substreams';
501-
}
502499
return true;
503500
},
504501
});
@@ -543,40 +540,34 @@ async function processInitForm(
543540
(!protocolInstance.hasContract() && !isComposedSubgraph),
544541
initial: initContract,
545542
validate: async (value: string) => {
546-
if (isComposedSubgraph) {
547-
return value.startsWith('Qm') ? true : 'Subgraph deployment ID must start with Qm';
548-
}
549-
550543
if (initFromExample !== undefined || !protocolInstance.hasContract()) {
551544
return true;
552545
}
553-
554-
const protocolContract = protocolInstance.getContract();
555-
if (!protocolContract) {
556-
return 'Contract not found.';
546+
if (isComposedSubgraph) {
547+
return value.startsWith('Qm') ? true : 'Subgraph deployment ID must start with Qm';
557548
}
558-
// Validate whether the contract is valid
559-
const { valid, error } = validateContract(value, protocolContract);
560549

550+
const { valid, error } = validateContract(value, protocolInstance.getContract()!);
561551
return valid ? true : error;
562552
},
563553
result: async (address: string) => {
564-
if (initFromExample !== undefined || isSubstreams || initAbiPath || isComposedSubgraph) {
554+
if (
555+
initFromExample !== undefined ||
556+
initAbiPath ||
557+
protocolInstance.name !== 'ethereum' // we can only validate against Etherscan API
558+
) {
565559
initDebugger("value: '%s'", address);
566560
return address;
567561
}
568562

569-
const ABI = protocolInstance.getABI();
570-
571-
// Try loading the ABI from Etherscan, if none was provided
563+
// If ABI is not provided, try to fetch it from Etherscan API
572564
if (protocolInstance.hasABIs() && !initAbi) {
573565
abiFromEtherscan = await retryWithPrompt(() =>
574-
contractService.getABI(ABI, networkId, address),
566+
contractService.getABI(protocolInstance.getABI(), networkId, address),
575567
);
576568
}
577-
// If startBlock is not set, try to load it.
569+
// If startBlock is not provided, try to fetch it from Etherscan API
578570
if (!initStartBlock) {
579-
// Load startBlock for this contract
580571
const startBlock = await retryWithPrompt(() =>
581572
contractService.getStartBlock(networkId, address),
582573
);
@@ -585,9 +576,8 @@ async function processInitForm(
585576
}
586577
}
587578

588-
// If contract name is not set, try to load it.
579+
// If contract name is not provided, try to fetch it from Etherscan API
589580
if (!initContractName) {
590-
// Load contract name for this contract
591581
const contractName = await retryWithPrompt(() =>
592582
contractService.getContractName(networkId, address),
593583
);

0 commit comments

Comments
 (0)