diff --git a/src/index.ts b/src/index.ts index 466ff72..aed3f0c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,8 +7,8 @@ import timeout from 'connect-timeout'; const app = express(); const PORT = process.argv[2] || 56666; -const maxErrorHandlingCount = 10; -let errorHandlingCount = 0; +// const maxErrorHandlingCount = 10; +// let errorHandlingCount = 0; const errorHandler = ( err: any, @@ -25,8 +25,11 @@ const errorHandler = ( }); } - services.initApi(); - logger.warn('📡 [global]: Connection reinitialized.'); + // services.initApi(); + // logger.warn('📡 [global]: Connection reinitialized.'); + logger.warn('📡 [global]: Apps go to reload.'); + // eslint-disable-next-line no-process-exit + process.exit(1); }; const loggingResponse = (_: Request, res: Response, next: NextFunction) => { @@ -65,15 +68,15 @@ app.post('/api/v1/swork/workreport', services.swork.reportWorks); app.use(errorHandler); process.on('uncaughtException', (err: Error) => { logger.error(`☄️ [global] Uncaught exception ${err.message}`); - if (++errorHandlingCount <= maxErrorHandlingCount) { - errorHandler(err, null, null, null); - } else { - logger.error( - 'Reach max error handling count, just exit and waitinng for restart' - ); - // eslint-disable-next-line no-process-exit - process.exit(1); - } + // if (++errorHandlingCount <= maxErrorHandlingCount) { + // errorHandler(err, null, null, null); + // } else { + // logger.error( + // 'Reach max error handling count, just exit and waitinng for restart' + // ); + // } + // eslint-disable-next-line no-process-exit + process.exit(1); }); app.listen(PORT, () => { diff --git a/src/services/util.ts b/src/services/util.ts index 199f913..b151d8c 100644 --- a/src/services/util.ts +++ b/src/services/util.ts @@ -31,13 +31,18 @@ export async function sendTx(tx: SubmittableExtrinsic, krp: KeyringPair) { ` ↪ 💸 [tx]: Transaction status: ${status.type}, nonce: ${tx.nonce}` ); - if (status.isInvalid || status.isDropped || status.isUsurped) { + if ( + status.isInvalid || + status.isDropped || + status.isUsurped || + status.isRetracted + ) { reject(new Error(`${status.type} transaction.`)); } else { // Pass it } - if (status.isInBlock) { + if (status.isFinalized) { events.forEach(({event: {data, method, section}}) => { if (section === 'system' && method === 'ExtrinsicFailed') { const [dispatchError] = data as unknown as ITuple<[DispatchError]>; @@ -85,6 +90,7 @@ export function queryToObj(queryRes: any) { export async function withApiReady(fn: Function, next: NextFunction) { const api = getApi(); + await sleep(1000); if (!api || !api.isConnected) { next(new Error('⚠️ Chain is offline, please connect a running chain.')); return;