Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
resolve(receipt)
},
undefined,
(error: any) => {
logMessage.error = error
exitTracerTool(logMessage)
}
)
})
const txReceipt: any = await transferToken
const txHash = txReceipt ? txReceipt.transactionHash : ''
// Need to wait for a bit to make sure that blockscout had enough time
// to see the transaction and display it
await sleep(BLOCKSCOUT_TIMEOUT)
logMessage.txHash = txHash
const handleError = (isError: boolean, data: { location: string; error: string }) => {
if (isError) {
exitTracerTool({ ...logMessage, ...data })
}
}
validateTransactionAndReceipt(from, txReceipt!, handleError)
await validateBlockscout(blockscoutUrl, txHash, from, handleError)
await validateGethRPC(web3, txHash, from, handleError)
}
TIME_TO_WAIT_FOR_ATTESTATIONS_IN_MINUTES &&
attestationsToComplete.length > 0
) {
const messages = await fetchLatestMessagesFromToday(client, phoneNumber, 100)
const res = await findValidCode(
attestations,
messages.map((_) => _.body),
phoneNumber,
attestationsToComplete,
account
)
if (!res) {
process.stdout.write('.')
await sleep(POLLING_WAIT)
continue
}
console.info('')
logger.info(
{ waitingTime: moment.duration(moment().diff(startDate)).asSeconds() },
'Received valid code'
)
const completeTx = await attestations.complete(phoneNumber, account, res.issuer, res.code)
await completeTx.sendAndWaitForReceipt(txParams)
logger.info({ issuer: res.issuer }, 'Completed attestation')
attestationsToComplete = await attestations.getActionableAttestations(phoneNumber, account)
}
txResult,
sendTransactionTime,
baseLogMessage,
blockscoutUrl,
blockscoutMeasurePercent
)
})
.catch((error: any) => {
console.error('Load test transaction failed with error:', JSON.stringify(error))
tracerLog({
tag: LOG_TAG_TRANSACTION_ERROR,
error: error.toString(),
...baseLogMessage,
})
})
await sleep(txPeriodMs)
}
}
if (!response.headers.has('X-RateLimit-Reset')) {
this.app.log.warning(`Bad response from GitHub API while requesting '${url}' URL (HTTP status is 403 but 'X-RateLimit-Reset' header is missing)`);
return undefined;
}
if (response.headers.get('X-RateLimit-Remaining') !== '0') {
this.app.log.warning(`Bad response from GitHub API while requesting '${url}' URL (HTTP status is 403 but 'X-RateLimit-Remaining' header is ${response.headers.get('X-RateLimit-Remaining')})`);
return undefined;
}
const resetTime = Number(response.headers.get('X-RateLimit-Reset')) * 1000;
let waitTime = resetTime - Date.now() + 1000;
if (waitTime <= 0) {
this.app.log.debug(`Bad response from GitHub API while requesting '${url}' URL (HTTP status is 403 but 'X-RateLimit-Reset' is before current time)`);
waitTime = 10000;
}
this.app.log.debug(`GitHub API limit reached, waiting ${waitTime / 1000} seconds...`);
await sleep(waitTime);
} else {
this.app.log.warning(`Bad response from GitHub API while requesting '${url}' URL (HTTP status: ${response.status})`);
return undefined;
}
}
}
}
const getFirstValidBlockscoutResponse = async (url: string, txHash: string) => {
const attempts = MAXIMAL_BLOCKSCOUT_TIMEOUT / BLOCKSCOUT_FETCH_RETRY_TIME
for (let attemptId = 0; attemptId < attempts; attemptId++) {
const json = await fetchBlockscoutTxInfo(url, txHash)
if (json.status !== '1') {
await sleep(BLOCKSCOUT_FETCH_RETRY_TIME)
} else {
return [json, Date.now()]
}
}
return [null, null]
}
async perform(): Promise {
const interval = Math.max(25, Math.round(chance.normal({mean: 300, dev: 250})));
await sleepAsync(interval);
throw new Error(`I failed after ${interval}ms.`);
}
}
if (isFailed(deploymentUpdate) || aliasError) {
debug(
aliasError
? 'Alias assignment error has occurred'
: 'Deployment has failed'
);
return yield {
type: 'error',
payload: aliasError
? deploymentUpdate.aliasError
: deploymentUpdate.error || deploymentUpdate,
};
}
}
await sleep(ms('1.5s'));
}
}
export async function sleepFor(p: TimeInterval): Promise {
return sleepAsync(intervalSplayDuration(p.interval, p.splay).shiftTo("seconds").seconds);
}
applyPropValues(propValues) {
const ps = Object.keys(propValues).map(name=>{
return this.mtpDevice.setPropValue(name, propValues[name])
});
return Promise.all(ps).then(Sleep(1000)).then(()=>{
return this.loadProperties();
});
}