diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index 6372dede5..8d7da31e6 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -5,6 +5,7 @@ "DB_USER": "mempool", "DB_PASSWORD": "mempool", "DB_DATABASE": "mempool", + "DB_DISABLED": false, "API_ENDPOINT": "/api/v1/", "ELECTRS_POLL_RATE_MS": 2000, "MEMPOOL_REFRESH_RATE_MS": 2000, diff --git a/backend/src/api/fee-api.ts b/backend/src/api/fee-api.ts index dfca7f96a..d3def77f9 100644 --- a/backend/src/api/fee-api.ts +++ b/backend/src/api/fee-api.ts @@ -1,5 +1,4 @@ import projectedBlocks from './mempool-blocks'; -import { DB } from '../database'; class FeeApi { constructor() { } @@ -28,20 +27,6 @@ class FeeApi { 'hourFee': thirdMedianFee, }; } - - public async $getTransactionsForBlock(blockHeight: number): Promise { - try { - const connection = await DB.pool.getConnection(); - const query = `SELECT feePerVsize AS fpv FROM transactions WHERE blockheight = ? ORDER BY feePerVsize ASC`; - const [rows] = await connection.query(query, [blockHeight]); - connection.release(); - return rows; - } catch (e) { - console.log('$getTransactionsForBlock() error', e); - return []; - } - } - } export default new FeeApi(); diff --git a/backend/src/database.ts b/backend/src/database.ts index a151ced49..9f30254ec 100644 --- a/backend/src/database.ts +++ b/backend/src/database.ts @@ -16,10 +16,10 @@ export class DB { export async function checkDbConnection() { try { const connection = await DB.pool.getConnection(); - console.log('MySQL connection established.'); + console.log('Database connection established.'); connection.release(); } catch (e) { - console.log('Could not connect to MySQL.'); + console.log('Could not connect to database.'); console.log(e); process.exit(1); } diff --git a/backend/src/index.ts b/backend/src/index.ts index 09371d54a..f5894f6c0 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -7,6 +7,7 @@ import * as http from 'http'; import * as https from 'https'; import * as WebSocket from 'ws'; +import { checkDbConnection } from './database'; import routes from './routes'; import blocks from './api/blocks'; import memPool from './api/mempool'; @@ -43,11 +44,15 @@ class Server { this.wss = new WebSocket.Server({ server: this.server }); } + if (!config.DB_DISABLED) { + checkDbConnection(); + statistics.startStatistics(); + } + this.setUpHttpApiRoutes(); this.setUpWebsocketHandling(); this.runMempoolIntervalFunctions(); - statistics.startStatistics(); fiatConversion.startService(); diskCache.loadMempoolCache();