diff --git a/src/constants.ts b/src/constants.ts index e8e6faf4..b8144bad 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -16,6 +16,8 @@ export const ALPHA_URL = "https://alpha4.starknet.io"; export const ALPHA_MAINNET_URL = "https://alpha-mainnet.starknet.io"; export const CHECK_STATUS_TIMEOUT = 5000; // ms +export const CHECK_STATUS_RECOVER_TIMEOUT = 10000; // ms + export const LEN_SUFFIX = "_len"; export const VOYAGER_GOERLI_CONTRACT_API_URL = "https://goerli.voyager.online/api/contract/"; export const VOYAGER_MAINNET_CONTRACT_API_URL = "https://voyager.online/api/contract/"; diff --git a/src/types.ts b/src/types.ts index c35ee3e6..623c63b6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ import * as fs from "fs"; import * as starknet from "./starknet-types"; import { HardhatPluginError } from "hardhat/plugins"; -import { PLUGIN_NAME, CHECK_STATUS_TIMEOUT, PENDING_BLOCK_NUMBER } from "./constants"; +import { PLUGIN_NAME, CHECK_STATUS_TIMEOUT, PENDING_BLOCK_NUMBER, CHECK_STATUS_RECOVER_TIMEOUT } from "./constants"; import { adaptLog } from "./utils"; import { adaptInput, adaptOutput } from "./adapt"; import { StarknetWrapper } from "./starknet-wrappers"; @@ -122,18 +122,26 @@ export async function iterativelyCheckStatus( resolve: (status: string) => void, reject: (reason?: any) => void ) { - const statusObject = await checkStatus(txHash, starknetWrapper, gatewayUrl, feederGatewayUrl); - if (isTxAccepted(statusObject)) { + const statusObject = await checkStatus(txHash, starknetWrapper, gatewayUrl, feederGatewayUrl) + .catch(reason => { + console.warn(reason); + return undefined; + }); + + if (!statusObject) { + console.warn("Retrying transaction status check..."); + // eslint-disable-next-line prefer-rest-params + setTimeout(iterativelyCheckStatus, CHECK_STATUS_RECOVER_TIMEOUT, ...arguments); + } else if (isTxAccepted(statusObject)) { resolve(statusObject.tx_status); } else if (isTxRejected(statusObject)) { reject(new Error("Transaction rejected. Error message:\n\n" + statusObject.tx_failure_reason.error_message)); } else { // Make a recursive call, but with a delay. // Local var `arguments` holds what was passed in the current call - const timeout = CHECK_STATUS_TIMEOUT; // ms // eslint-disable-next-line prefer-rest-params - setTimeout(iterativelyCheckStatus, timeout, ...arguments); + setTimeout(iterativelyCheckStatus, CHECK_STATUS_TIMEOUT, ...arguments); } }