Skip to content

Commit ec12f21

Browse files
authored
Backend: Bumping Typescript version to 4.4.2 (mempool#748)
* Backend: Bumping Typescript version to 4.4.2 * Replacing any types with instanceOf checks.
1 parent 2e8ecc7 commit ec12f21

17 files changed

+73
-63
lines changed

.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.tabSize": 2,
3+
"typescript.tsdk": "./backend/node_modules/typescript/lib"
4+
}

backend/.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.tabSize": 2,
3+
"typescript.tsdk": "../backend/node_modules/typescript/lib"
4+
}

backend/package-lock.json

+10-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@
4545
"@types/locutus": "^0.0.6",
4646
"@types/ws": "^7.4.4",
4747
"tslint": "^6.1.0",
48-
"typescript": "^4.1.5"
48+
"typescript": "4.4.2"
4949
}
5050
}

backend/src/api/backend-info.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BackendInfo {
3030
try {
3131
this.gitCommitHash = fs.readFileSync('../.git/refs/heads/master').toString().trim();
3232
} catch (e) {
33-
logger.err('Could not load git commit info: ' + e.message || e);
33+
logger.err('Could not load git commit info: ' + (e instanceof Error ? e.message : e));
3434
}
3535
}
3636

@@ -39,7 +39,7 @@ class BackendInfo {
3939
const packageJson = fs.readFileSync('package.json').toString();
4040
this.version = JSON.parse(packageJson).version;
4141
} catch (e) {
42-
throw new Error(e);
42+
throw new Error(e instanceof Error ? e.message : 'Error');
4343
}
4444
}
4545
}

backend/src/api/bisq/bisq.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class Bisq {
162162
this.buildIndex();
163163
this.calculateStats();
164164
} catch (e) {
165-
logger.info('loadBisqDumpFile() error.' + e.message || e);
165+
logger.info('loadBisqDumpFile() error.' + (e instanceof Error ? e.message : e));
166166
}
167167
}
168168

backend/src/api/bisq/markets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Bisq {
102102
logger.debug('Bisq market data updated in ' + time + ' ms');
103103
}
104104
} catch (e) {
105-
logger.err('loadBisqMarketDataDumpFile() error.' + e.message || e);
105+
logger.err('loadBisqMarketDataDumpFile() error.' + (e instanceof Error ? e.message : e));
106106
}
107107
}
108108

backend/src/api/bitcoin/electrum-api.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
9393
if (e === 'failed to get confirmed status') {
9494
e = 'The number of transactions on this address exceeds the Electrum server limit';
9595
}
96-
throw new Error(e);
96+
throw new Error(e instanceof Error ? e.message : 'Error');
9797
}
9898
}
9999

@@ -131,7 +131,7 @@ class BitcoindElectrsApi extends BitcoinApi implements AbstractBitcoinApi {
131131
if (e === 'failed to get confirmed status') {
132132
e = 'The number of transactions on this address exceeds the Electrum server limit';
133133
}
134-
throw new Error(e);
134+
throw new Error(e instanceof Error ? e.message : 'Error');
135135
}
136136
}
137137

backend/src/api/blocks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Blocks {
8989
const tx = await transactionUtils.$getTransactionExtended(txIds[i]);
9090
transactions.push(tx);
9191
} catch (e) {
92-
logger.debug('Error fetching block tx: ' + e.message || e);
92+
logger.debug('Error fetching block tx: ' + (e instanceof Error ? e.message : e));
9393
if (i === 0) {
9494
throw new Error('Failed to fetch Coinbase transaction: ' + txIds[i]);
9595
}

backend/src/api/disk-cache.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class DiskCache {
5252
logger.debug('Mempool and blocks data saved to disk cache');
5353
this.isWritingCache = false;
5454
} catch (e) {
55-
logger.warn('Error writing to cache file: ' + e.message || e);
55+
logger.warn('Error writing to cache file: ' + (e instanceof Error ? e.message : e));
5656
this.isWritingCache = false;
5757
}
5858
}

backend/src/api/fiat-conversion.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FiatConversion {
3636
this.ratesChangedCallback(this.conversionRates);
3737
}
3838
} catch (e) {
39-
logger.err('Error updating fiat conversion rates: ' + e);
39+
logger.err('Error updating fiat conversion rates: ' + (e instanceof Error ? e.message : e));
4040
}
4141
}
4242
}

backend/src/api/mempool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Mempool {
124124
}
125125
newTransactions.push(transaction);
126126
} catch (e) {
127-
logger.debug('Error finding transaction in mempool: ' + e.message || e);
127+
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
128128
}
129129
}
130130

backend/src/api/statistics.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class Statistics {
255255
connection.release();
256256
return result.insertId;
257257
} catch (e) {
258-
logger.err('$create() error' + e.message || e);
258+
logger.err('$create() error' + (e instanceof Error ? e.message : e));
259259
}
260260
}
261261

@@ -313,7 +313,7 @@ class Statistics {
313313
return this.mapStatisticToOptimizedStatistic([rows[0]])[0];
314314
}
315315
} catch (e) {
316-
logger.err('$list2H() error' + e.message || e);
316+
logger.err('$list2H() error' + (e instanceof Error ? e.message : e));
317317
}
318318
}
319319

@@ -325,7 +325,7 @@ class Statistics {
325325
connection.release();
326326
return this.mapStatisticToOptimizedStatistic(rows);
327327
} catch (e) {
328-
logger.err('$list2H() error' + e.message || e);
328+
logger.err('$list2H() error' + (e instanceof Error ? e.message : e));
329329
return [];
330330
}
331331
}
@@ -338,7 +338,7 @@ class Statistics {
338338
connection.release();
339339
return this.mapStatisticToOptimizedStatistic(rows);
340340
} catch (e) {
341-
logger.err('$list24h() error' + e.message || e);
341+
logger.err('$list24h() error' + (e instanceof Error ? e.message : e));
342342
return [];
343343
}
344344
}
@@ -351,7 +351,7 @@ class Statistics {
351351
connection.release();
352352
return this.mapStatisticToOptimizedStatistic(rows);
353353
} catch (e) {
354-
logger.err('$list1W() error' + e);
354+
logger.err('$list1W() error' + (e instanceof Error ? e.message : e));
355355
return [];
356356
}
357357
}
@@ -364,7 +364,7 @@ class Statistics {
364364
connection.release();
365365
return this.mapStatisticToOptimizedStatistic(rows);
366366
} catch (e) {
367-
logger.err('$list1M() error' + e);
367+
logger.err('$list1M() error' + (e instanceof Error ? e.message : e));
368368
return [];
369369
}
370370
}
@@ -377,7 +377,7 @@ class Statistics {
377377
connection.release();
378378
return this.mapStatisticToOptimizedStatistic(rows);
379379
} catch (e) {
380-
logger.err('$list3M() error' + e);
380+
logger.err('$list3M() error' + (e instanceof Error ? e.message : e));
381381
return [];
382382
}
383383
}
@@ -390,7 +390,7 @@ class Statistics {
390390
connection.release();
391391
return this.mapStatisticToOptimizedStatistic(rows);
392392
} catch (e) {
393-
logger.err('$list6M() error' + e);
393+
logger.err('$list6M() error' + (e instanceof Error ? e.message : e));
394394
return [];
395395
}
396396
}
@@ -403,7 +403,7 @@ class Statistics {
403403
connection.release();
404404
return this.mapStatisticToOptimizedStatistic(rows);
405405
} catch (e) {
406-
logger.err('$list6M() error' + e);
406+
logger.err('$list6M() error' + (e instanceof Error ? e.message : e));
407407
return [];
408408
}
409409
}

backend/src/api/websocket-handler.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ class WebsocketHandler {
6161
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
6262
response['tx'] = fullTx;
6363
} catch (e) {
64-
logger.debug('Error finding transaction: ' + e.message || e);
64+
logger.debug('Error finding transaction: ' + (e instanceof Error ? e.message : e));
6565
}
6666
}
6767
} else {
6868
try {
6969
const fullTx = await transactionUtils.$getTransactionExtended(client['track-tx'], true);
7070
response['tx'] = fullTx;
7171
} catch (e) {
72-
logger.debug('Error finding transaction. ' + e.message || e);
72+
logger.debug('Error finding transaction. ' + (e instanceof Error ? e.message : e));
7373
client['track-mempool-tx'] = parsedMessage['track-tx'];
7474
}
7575
}
@@ -124,7 +124,7 @@ class WebsocketHandler {
124124
client.send(JSON.stringify(response));
125125
}
126126
} catch (e) {
127-
logger.debug('Error parsing websocket message: ' + e.message || e);
127+
logger.debug('Error parsing websocket message: ' + (e instanceof Error ? e.message : e));
128128
}
129129
});
130130
});
@@ -252,7 +252,7 @@ class WebsocketHandler {
252252
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
253253
response['tx'] = fullTx;
254254
} catch (e) {
255-
logger.debug('Error finding transaction in mempool: ' + e.message || e);
255+
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
256256
}
257257
} else {
258258
response['tx'] = tx;
@@ -272,7 +272,7 @@ class WebsocketHandler {
272272
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
273273
foundTransactions.push(fullTx);
274274
} catch (e) {
275-
logger.debug('Error finding transaction in mempool: ' + e.message || e);
275+
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
276276
}
277277
} else {
278278
foundTransactions.push(tx);
@@ -286,7 +286,7 @@ class WebsocketHandler {
286286
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
287287
foundTransactions.push(fullTx);
288288
} catch (e) {
289-
logger.debug('Error finding transaction in mempool: ' + e.message || e);
289+
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
290290
}
291291
} else {
292292
foundTransactions.push(tx);
@@ -337,7 +337,7 @@ class WebsocketHandler {
337337
const fullTx = await transactionUtils.$getTransactionExtended(rbfTransaction, true);
338338
response['rbfTransaction'] = fullTx;
339339
} catch (e) {
340-
logger.debug('Error finding transaction in mempool: ' + e.message || e);
340+
logger.debug('Error finding transaction in mempool: ' + (e instanceof Error ? e.message : e));
341341
}
342342
} else {
343343
response['rbfTransaction'] = rbfTx;

backend/src/database.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function checkDbConnection() {
2020
logger.info('Database connection established.');
2121
connection.release();
2222
} catch (e) {
23-
logger.err('Could not connect to database: ' + e.message || e);
23+
logger.err('Could not connect to database: ' + (e instanceof Error ? e.message : e));
2424
process.exit(1);
2525
}
2626
}

backend/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Server {
111111
try {
112112
await memPool.$updateMemPoolInfo();
113113
} catch (e) {
114-
const msg = `updateMempoolInfo: ${(e.message || e)}`;
114+
const msg = `updateMempoolInfo: ${(e instanceof Error ? e.message : e)}`;
115115
if (config.CORE_RPC_MINFEE.ENABLED) {
116116
logger.warn(msg);
117117
} else {
@@ -123,7 +123,7 @@ class Server {
123123
setTimeout(this.runMainUpdateLoop.bind(this), config.MEMPOOL.POLL_RATE_MS);
124124
this.currentBackendRetryInterval = 5;
125125
} catch (e) {
126-
const loggerMsg = `runMainLoop error: ${(e.message || e)}. Retrying in ${this.currentBackendRetryInterval} sec.`;
126+
const loggerMsg = `runMainLoop error: ${(e instanceof Error ? e.message : e)}. Retrying in ${this.currentBackendRetryInterval} sec.`;
127127
if (this.currentBackendRetryInterval > 5) {
128128
logger.warn(loggerMsg);
129129
mempool.setOutOfSync();

0 commit comments

Comments
 (0)