@@ -2,6 +2,7 @@ import fs from 'fs';
2
2
import os from 'os' ;
3
3
import path from 'path' ;
4
4
import { filesystem , prompt , system } from 'gluegun' ;
5
+ import * as toolbox from 'gluegun' ;
5
6
import { Args , Command , Flags , ux } from '@oclif/core' ;
6
7
import {
7
8
loadAbiFromBlockScout ,
@@ -395,6 +396,26 @@ async function processFromExampleInitForm(
395
396
}
396
397
}
397
398
399
+ async function retryWithPrompt < T > ( func : ( ) => Promise < T > ) : Promise < T | undefined > {
400
+ for ( ; ; ) {
401
+ try {
402
+ return await func ( ) ;
403
+ } catch ( _ ) {
404
+ const { retry } = await toolbox . prompt . ask ( {
405
+ type : 'confirm' ,
406
+ name : 'retry' ,
407
+ message : 'Do you want to retry?' ,
408
+ initial : true ,
409
+ } ) ;
410
+
411
+ if ( ! retry ) {
412
+ break ;
413
+ }
414
+ }
415
+ }
416
+ return undefined ;
417
+ }
418
+
398
419
async function processInitForm (
399
420
this : InitCommand ,
400
421
{
@@ -585,24 +606,24 @@ async function processInitForm(
585
606
586
607
// Try loading the ABI from Etherscan, if none was provided
587
608
if ( protocolInstance . hasABIs ( ) && ! initAbi ) {
588
- try {
589
- if ( network === 'poa-core' ) {
590
- // TODO: this variable is never used anywhere, what happens?
591
- // abiFromBlockScout = await loadAbiFromBlockScout(ABI, network, value)
592
- } else {
593
- abiFromEtherscan = await loadAbiFromEtherscan ( ABI , network , value ) ;
594
- }
595
- } catch ( e ) {
596
- // noop
609
+ if ( network === 'poa-core' ) {
610
+ abiFromEtherscan = await retryWithPrompt ( ( ) =>
611
+ loadAbiFromBlockScout ( ABI , network , value ) ,
612
+ ) ;
613
+ } else {
614
+ abiFromEtherscan = await retryWithPrompt ( ( ) =>
615
+ loadAbiFromEtherscan ( ABI , network , value ) ,
616
+ ) ;
597
617
}
598
618
}
599
619
// If startBlock is not set, try to load it.
600
620
if ( ! initStartBlock ) {
601
- try {
602
- // Load startBlock for this contract
603
- initStartBlock = Number ( await loadStartBlockForContract ( network , value ) ) . toString ( ) ;
604
- } catch ( error ) {
605
- // noop
621
+ // Load startBlock for this contract
622
+ const startBlock = await retryWithPrompt ( ( ) =>
623
+ loadStartBlockForContract ( network , value ) ,
624
+ ) ;
625
+ if ( startBlock ) {
626
+ initStartBlock = Number ( startBlock ) . toString ( ) ;
606
627
}
607
628
}
608
629
return value ;
0 commit comments