Add setting to disable database use.

This commit is contained in:
softsimon 2020-07-23 00:04:29 +07:00
parent 251b8cdd8d
commit 86c0a5ec7b
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
4 changed files with 9 additions and 18 deletions

View File

@ -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,

View File

@ -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<any[]> {
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<any>(query, [blockHeight]);
connection.release();
return rows;
} catch (e) {
console.log('$getTransactionsForBlock() error', e);
return [];
}
}
}
export default new FeeApi();

View File

@ -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);
}

View File

@ -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();