Add setting to disable database use.
This commit is contained in:
		
							parent
							
								
									251b8cdd8d
								
							
						
					
					
						commit
						86c0a5ec7b
					
				@ -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,
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user