diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..06578f8f1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.tabSize": 2, + "typescript.tsdk": "./backend/node_modules/typescript/lib" +} \ No newline at end of file diff --git a/backend/.vscode/settings.json b/backend/.vscode/settings.json new file mode 100644 index 000000000..41e35fc77 --- /dev/null +++ b/backend/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.tabSize": 2, + "typescript.tsdk": "../backend/node_modules/typescript/lib" +} \ No newline at end of file diff --git a/backend/package-lock.json b/backend/package-lock.json index 9cb6d20fc..abd99be77 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -26,7 +26,7 @@ "@types/locutus": "^0.0.6", "@types/ws": "^7.4.4", "tslint": "^6.1.0", - "typescript": "^4.1.5" + "typescript": "4.4.2" } }, "node_modules/@babel/code-frame": { @@ -1473,10 +1473,11 @@ "integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==" }, "node_modules/typescript": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", - "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz", + "integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -2770,9 +2771,9 @@ "integrity": "sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g==" }, "typescript": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz", - "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==", + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz", + "integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==", "dev": true }, "unpipe": { @@ -2820,7 +2821,8 @@ "ws": { "version": "7.4.6", "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==" + "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "requires": {} }, "yallist": { "version": "4.0.0", diff --git a/backend/package.json b/backend/package.json index 24e6dfe2f..2ca7531b1 100644 --- a/backend/package.json +++ b/backend/package.json @@ -45,6 +45,6 @@ "@types/locutus": "^0.0.6", "@types/ws": "^7.4.4", "tslint": "^6.1.0", - "typescript": "^4.1.5" + "typescript": "4.4.2" } } diff --git a/backend/src/api/backend-info.ts b/backend/src/api/backend-info.ts index 7c6456522..5a556ef18 100644 --- a/backend/src/api/backend-info.ts +++ b/backend/src/api/backend-info.ts @@ -30,7 +30,7 @@ class BackendInfo { try { this.gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim(); } catch (e) { - logger.err('Could not load git commit info: ' + e.message || e); + logger.err('Could not load git commit info: ' + (e instanceof Error ? e.message : e)); } } @@ -39,7 +39,7 @@ class BackendInfo { const packageJson = fs.readFileSync('package.json').toString(); this.version = JSON.parse(packageJson).version; } catch (e) { - throw new Error(e); + throw new Error(e instanceof Error ? e.message : 'Error'); } } } diff --git a/backend/src/api/bisq/bisq.ts b/backend/src/api/bisq/bisq.ts index df8314fc1..e189b33cf 100644 --- a/backend/src/api/bisq/bisq.ts +++ b/backend/src/api/bisq/bisq.ts @@ -162,7 +162,7 @@ class Bisq { this.buildIndex(); this.calculateStats(); } catch (e) { - logger.info('loadBisqDumpFile() error.' + e.message || e); + logger.info('loadBisqDumpFile() error.' + (e instanceof Error ? e.message : e)); } } diff --git a/backend/src/api/bisq/markets.ts b/backend/src/api/bisq/markets.ts index beac44851..765063a43 100644 --- a/backend/src/api/bisq/markets.ts +++ b/backend/src/api/bisq/markets.ts @@ -102,7 +102,7 @@ class Bisq { logger.debug('Bisq market data updated in ' + time + ' ms'); } } catch (e) { - logger.err('loadBisqMarketDataDumpFile() error.' + e.message || e); + logger.err('loadBisqMarketDataDumpFile() error.' + (e instanceof Error ? e.message : e)); } } diff --git a/backend/src/api/bitcoin/electrum-api.ts b/backend/src/api/bitcoin/electrum-api.ts index 2d1e97d9a..8de667222 100644 --- a/backend/src/api/bitcoin/electrum-api.ts +++ b/backend/src/api/bitcoin/electrum-api.ts @@ -93,7 +93,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi { if (e === 'failed to get confirmed status') { e = 'The number of transactions on this address exceeds the Electrum server limit'; } - throw new Error(e); + throw new Error(e instanceof Error ? e.message : 'Error'); } } @@ -131,7 +131,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi { if (e === 'failed to get confirmed status') { e = 'The number of transactions on this address exceeds the Electrum server limit'; } - throw new Error(e); + throw new Error(e instanceof Error ? e.message : 'Error'); } } diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index b09a5ac06..785bc12eb 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -89,7 +89,7 @@ class Blocks { const tx = await transactionUtils.$getTransactionExtended(txIds[i]); transactions.push(tx); } catch (e) { - logger.debug('Error fetching block tx: ' + e.message || e); + logger.debug('Error fetching block tx: ' + (e instanceof Error ? e.message : e)); if (i === 0) { throw new Error('Failed to fetch Coinbase transaction: ' + txIds[i]); } diff --git a/backend/src/api/disk-cache.ts b/backend/src/api/disk-cache.ts index ca15bd681..0774f0904 100644 --- a/backend/src/api/disk-cache.ts +++ b/backend/src/api/disk-cache.ts @@ -52,7 +52,7 @@ class DiskCache { logger.debug('Mempool and blocks data saved to disk cache'); this.isWritingCache = false; } catch (e) { - logger.warn('Error writing to cache file: ' + e.message || e); + logger.warn('Error writing to cache file: ' + (e instanceof Error ? e.message : e)); this.isWritingCache = false; } } diff --git a/backend/src/api/fiat-conversion.ts b/backend/src/api/fiat-conversion.ts index 0d242f3cd..d779e31fd 100644 --- a/backend/src/api/fiat-conversion.ts +++ b/backend/src/api/fiat-conversion.ts @@ -36,7 +36,7 @@ class FiatConversion { this.ratesChangedCallback(this.conversionRates); } } catch (e) { - logger.err('Error updating fiat conversion rates: ' + e); + logger.err('Error updating fiat conversion rates: ' + (e instanceof Error ? e.message : e)); } } } diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index 81330a3ce..30a3ad356 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -124,7 +124,7 @@ class Mempool { } newTransactions.push(transaction); } catch (e) { - logger.debug('Error finding transaction in mempool: ' + e.message || e); + logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e)); } } diff --git a/backend/src/api/statistics.ts b/backend/src/api/statistics.ts index 468f136b9..521e1536d 100644 --- a/backend/src/api/statistics.ts +++ b/backend/src/api/statistics.ts @@ -255,7 +255,7 @@ class Statistics { connection.release(); return result.insertId; } catch (e) { - logger.err('$create() error' + e.message || e); + logger.err('$create() error' + (e instanceof Error ? e.message : e)); } } @@ -313,7 +313,7 @@ class Statistics { return this.mapStatisticToOptimizedStatistic([rows[0]])[0]; } } catch (e) { - logger.err('$list2H() error' + e.message || e); + logger.err('$list2H() error' + (e instanceof Error ? e.message : e)); } } @@ -325,7 +325,7 @@ class Statistics { connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { - logger.err('$list2H() error' + e.message || e); + logger.err('$list2H() error' + (e instanceof Error ? e.message : e)); return []; } } @@ -338,7 +338,7 @@ class Statistics { connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { - logger.err('$list24h() error' + e.message || e); + logger.err('$list24h() error' + (e instanceof Error ? e.message : e)); return []; } } @@ -351,7 +351,7 @@ class Statistics { connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { - logger.err('$list1W() error' + e); + logger.err('$list1W() error' + (e instanceof Error ? e.message : e)); return []; } } @@ -364,7 +364,7 @@ class Statistics { connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { - logger.err('$list1M() error' + e); + logger.err('$list1M() error' + (e instanceof Error ? e.message : e)); return []; } } @@ -377,7 +377,7 @@ class Statistics { connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { - logger.err('$list3M() error' + e); + logger.err('$list3M() error' + (e instanceof Error ? e.message : e)); return []; } } @@ -390,7 +390,7 @@ class Statistics { connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { - logger.err('$list6M() error' + e); + logger.err('$list6M() error' + (e instanceof Error ? e.message : e)); return []; } } @@ -403,7 +403,7 @@ class Statistics { connection.release(); return this.mapStatisticToOptimizedStatistic(rows); } catch (e) { - logger.err('$list6M() error' + e); + logger.err('$list6M() error' + (e instanceof Error ? e.message : e)); return []; } } diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index 29a2ed363..0f7445aef 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -61,7 +61,7 @@ class WebsocketHandler { const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true); response['tx'] = fullTx; } catch (e) { - logger.debug('Error finding transaction: ' + e.message || e); + logger.debug('Error finding transaction: ' + (e instanceof Error ? e.message : e)); } } } else { @@ -69,7 +69,7 @@ class WebsocketHandler { const fullTx = await transactionUtils.$getTransactionExtended(client['track-tx'], true); response['tx'] = fullTx; } catch (e) { - logger.debug('Error finding transaction. ' + e.message || e); + logger.debug('Error finding transaction. ' + (e instanceof Error ? e.message : e)); client['track-mempool-tx'] = parsedMessage['track-tx']; } } @@ -124,7 +124,7 @@ class WebsocketHandler { client.send(JSON.stringify(response)); } } catch (e) { - logger.debug('Error parsing websocket message: ' + e.message || e); + logger.debug('Error parsing websocket message: ' + (e instanceof Error ? e.message : e)); } }); }); @@ -252,7 +252,7 @@ class WebsocketHandler { const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true); response['tx'] = fullTx; } catch (e) { - logger.debug('Error finding transaction in mempool: ' + e.message || e); + logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e)); } } else { response['tx'] = tx; @@ -272,7 +272,7 @@ class WebsocketHandler { const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true); foundTransactions.push(fullTx); } catch (e) { - logger.debug('Error finding transaction in mempool: ' + e.message || e); + logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e)); } } else { foundTransactions.push(tx); @@ -286,7 +286,7 @@ class WebsocketHandler { const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true); foundTransactions.push(fullTx); } catch (e) { - logger.debug('Error finding transaction in mempool: ' + e.message || e); + logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e)); } } else { foundTransactions.push(tx); @@ -337,7 +337,7 @@ class WebsocketHandler { const fullTx = await transactionUtils.$getTransactionExtended(rbfTransaction, true); response['rbfTransaction'] = fullTx; } catch (e) { - logger.debug('Error finding transaction in mempool: ' + e.message || e); + logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e)); } } else { response['rbfTransaction'] = rbfTx; diff --git a/backend/src/database.ts b/backend/src/database.ts index f288fcfa3..b0d39b301 100644 --- a/backend/src/database.ts +++ b/backend/src/database.ts @@ -20,7 +20,7 @@ export async function checkDbConnection() { logger.info('Database connection established.'); connection.release(); } catch (e) { - logger.err('Could not connect to database: ' + e.message || e); + logger.err('Could not connect to database: ' + (e instanceof Error ? e.message : e)); process.exit(1); } } diff --git a/backend/src/index.ts b/backend/src/index.ts index f3a06d7d5..e71931e83 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -111,7 +111,7 @@ class Server { try { await memPool.$updateMemPoolInfo(); } catch (e) { - const msg = `updateMempoolInfo: ${(e.message || e)}`; + const msg = `updateMempoolInfo: ${(e instanceof Error ? e.message : e)}`; if (config.CORE_RPC_MINFEE.ENABLED) { logger.warn(msg); } else { @@ -123,7 +123,7 @@ class Server { setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS); this.currentBackendRetryInterval = 5; } catch (e) { - const loggerMsg = `runMainLoop error: ${(e.message || e)}. Retrying in ${this.currentBackendRetryInterval} sec.`; + const loggerMsg = `runMainLoop error: ${(e instanceof Error ? e.message : e)}. Retrying in ${this.currentBackendRetryInterval} sec.`; if (this.currentBackendRetryInterval > 5) { logger.warn(loggerMsg); mempool.setOutOfSync(); diff --git a/backend/src/routes.ts b/backend/src/routes.ts index e6bd416bf..3b374f788 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -55,7 +55,7 @@ class Routes { const result = websocketHandler.getInitData(); res.json(result); } catch (e) { - res.status(500).send(e.message); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -74,7 +74,7 @@ class Routes { const result = mempoolBlocks.getMempoolBlocks(); res.json(result); } catch (e) { - res.status(500).send(e.message); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -477,10 +477,10 @@ class Routes { res.json(transaction); } catch (e) { let statusCode = 500; - if (e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) { + if (e instanceof Error && e instanceof Error && e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) { statusCode = 404; } - res.status(statusCode).send(e.message || e); + res.status(statusCode).send(e instanceof Error ? e.message : e); } } @@ -491,10 +491,10 @@ class Routes { res.send(transaction.hex); } catch (e) { let statusCode = 500; - if (e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) { + if (e instanceof Error && e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) { statusCode = 404; } - res.status(statusCode).send(e.message || e); + res.status(statusCode).send(e instanceof Error ? e.message : e); } } @@ -504,10 +504,10 @@ class Routes { res.json(transaction.status); } catch (e) { let statusCode = 500; - if (e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) { + if (e instanceof Error && e.message && e.message.indexOf('No such mempool or blockchain transaction') > -1) { statusCode = 404; } - res.status(statusCode).send(e.message || e); + res.status(statusCode).send(e instanceof Error ? e.message : e); } } @@ -516,7 +516,7 @@ class Routes { const result = await bitcoinApi.$getBlock(req.params.hash); res.json(result); } catch (e) { - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -526,7 +526,7 @@ class Routes { res.setHeader('content-type', 'text/plain'); res.send(blockHeader); } catch (e) { - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -563,7 +563,7 @@ class Routes { res.json(returnBlocks); } catch (e) { loadingIndicators.setProgress('blocks', 100); - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -582,13 +582,13 @@ class Routes { transactions.push(transaction); loadingIndicators.setProgress('blocktxs-' + req.params.hash, (i + 1) / endIndex * 100); } catch (e) { - logger.debug('getBlockTransactions error: ' + e.message || e); + logger.debug('getBlockTransactions error: ' + (e instanceof Error ? e.message : e)); } } res.json(transactions); } catch (e) { loadingIndicators.setProgress('blocktxs-' + req.params.hash, 100); - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -597,7 +597,7 @@ class Routes { const blockHash = await bitcoinApi.$getBlockHash(parseInt(req.params.height, 10)); res.send(blockHash); } catch (e) { - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -611,10 +611,10 @@ class Routes { const addressData = await bitcoinApi.$getAddress(req.params.address); res.json(addressData); } catch (e) { - if (e.message && e.message.indexOf('exceeds') > 0) { - return res.status(413).send(e.message); + if (e instanceof Error && e.message && e.message.indexOf('exceeds') > 0) { + return res.status(413).send(e instanceof Error ? e.message : e); } - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -628,10 +628,10 @@ class Routes { const transactions = await bitcoinApi.$getAddressTransactions(req.params.address, req.params.txId); res.json(transactions); } catch (e) { - if (e.message && e.message.indexOf('exceeds') > 0) { - return res.status(413).send(e.message); + if (e instanceof Error && e.message && e.message.indexOf('exceeds') > 0) { + return res.status(413).send(e instanceof Error ? e.message : e); } - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -644,7 +644,7 @@ class Routes { const blockHash = await bitcoinApi.$getAddressPrefix(req.params.prefix); res.send(blockHash); } catch (e) { - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -665,7 +665,7 @@ class Routes { const rawMempool = await bitcoinApi.$getRawMempool(); res.send(rawMempool); } catch (e) { - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -674,7 +674,7 @@ class Routes { const result = await bitcoinApi.$getBlockHeightTip(); res.json(result); } catch (e) { - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -683,7 +683,7 @@ class Routes { const result = await bitcoinApi.$getTxIdsForBlock(req.params.hash); res.json(result); } catch (e) { - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } @@ -741,7 +741,7 @@ class Routes { res.json(result); } catch (e) { - res.status(500).send(e.message || e); + res.status(500).send(e instanceof Error ? e.message : e); } } }