parent
							
								
									5f87cc6d37
								
							
						
					
					
						commit
						b31642e554
					
				@ -2,6 +2,7 @@
 | 
				
			|||||||
  "MEMPOOL": {
 | 
					  "MEMPOOL": {
 | 
				
			||||||
    "NETWORK": "mainnet",
 | 
					    "NETWORK": "mainnet",
 | 
				
			||||||
    "BACKEND": "electrum",
 | 
					    "BACKEND": "electrum",
 | 
				
			||||||
 | 
					    "ENABLED": true,
 | 
				
			||||||
    "HTTP_PORT": 8999,
 | 
					    "HTTP_PORT": 8999,
 | 
				
			||||||
    "SPAWN_CLUSTER_PROCS": 0,
 | 
					    "SPAWN_CLUSTER_PROCS": 0,
 | 
				
			||||||
    "API_URL_PREFIX": "/api/v1/",
 | 
					    "API_URL_PREFIX": "/api/v1/",
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ const configFromFile = require(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
interface IConfig {
 | 
					interface IConfig {
 | 
				
			||||||
  MEMPOOL: {
 | 
					  MEMPOOL: {
 | 
				
			||||||
 | 
					    ENABLED: boolean;
 | 
				
			||||||
    NETWORK: 'mainnet' | 'testnet' | 'signet' | 'liquid' | 'liquidtestnet';
 | 
					    NETWORK: 'mainnet' | 'testnet' | 'signet' | 'liquid' | 'liquidtestnet';
 | 
				
			||||||
    BACKEND: 'esplora' | 'electrum' | 'none';
 | 
					    BACKEND: 'esplora' | 'electrum' | 'none';
 | 
				
			||||||
    HTTP_PORT: number;
 | 
					    HTTP_PORT: number;
 | 
				
			||||||
@ -119,6 +120,7 @@ interface IConfig {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const defaults: IConfig = {
 | 
					const defaults: IConfig = {
 | 
				
			||||||
  'MEMPOOL': {
 | 
					  'MEMPOOL': {
 | 
				
			||||||
 | 
					    'ENABLED': true,
 | 
				
			||||||
    'NETWORK': 'mainnet',
 | 
					    'NETWORK': 'mainnet',
 | 
				
			||||||
    'BACKEND': 'none',
 | 
					    'BACKEND': 'none',
 | 
				
			||||||
    'HTTP_PORT': 8999,
 | 
					    'HTTP_PORT': 8999,
 | 
				
			||||||
@ -224,11 +226,11 @@ const defaults: IConfig = {
 | 
				
			|||||||
    'BISQ_URL': 'https://bisq.markets/api',
 | 
					    'BISQ_URL': 'https://bisq.markets/api',
 | 
				
			||||||
    'BISQ_ONION': 'http://bisqmktse2cabavbr2xjq7xw3h6g5ottemo5rolfcwt6aly6tp5fdryd.onion/api'
 | 
					    'BISQ_ONION': 'http://bisqmktse2cabavbr2xjq7xw3h6g5ottemo5rolfcwt6aly6tp5fdryd.onion/api'
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "MAXMIND": {
 | 
					  'MAXMIND': {
 | 
				
			||||||
    'ENABLED': false,
 | 
					    'ENABLED': false,
 | 
				
			||||||
    "GEOLITE2_CITY": "/usr/local/share/GeoIP/GeoLite2-City.mmdb",
 | 
					    'GEOLITE2_CITY': '/usr/local/share/GeoIP/GeoLite2-City.mmdb',
 | 
				
			||||||
    "GEOLITE2_ASN": "/usr/local/share/GeoIP/GeoLite2-ASN.mmdb",
 | 
					    'GEOLITE2_ASN': '/usr/local/share/GeoIP/GeoLite2-ASN.mmdb',
 | 
				
			||||||
    "GEOIP2_ISP": "/usr/local/share/GeoIP/GeoIP2-ISP.mmdb"
 | 
					    'GEOIP2_ISP': '/usr/local/share/GeoIP/GeoIP2-ISP.mmdb'
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,4 @@
 | 
				
			|||||||
import express from "express";
 | 
					import express from 'express';
 | 
				
			||||||
import { Application, Request, Response, NextFunction } from 'express';
 | 
					import { Application, Request, Response, NextFunction } from 'express';
 | 
				
			||||||
import * as http from 'http';
 | 
					import * as http from 'http';
 | 
				
			||||||
import * as WebSocket from 'ws';
 | 
					import * as WebSocket from 'ws';
 | 
				
			||||||
@ -34,7 +34,7 @@ import miningRoutes from './api/mining/mining-routes';
 | 
				
			|||||||
import bisqRoutes from './api/bisq/bisq.routes';
 | 
					import bisqRoutes from './api/bisq/bisq.routes';
 | 
				
			||||||
import liquidRoutes from './api/liquid/liquid.routes';
 | 
					import liquidRoutes from './api/liquid/liquid.routes';
 | 
				
			||||||
import bitcoinRoutes from './api/bitcoin/bitcoin.routes';
 | 
					import bitcoinRoutes from './api/bitcoin/bitcoin.routes';
 | 
				
			||||||
import fundingTxFetcher from "./tasks/lightning/sync-tasks/funding-tx-fetcher";
 | 
					import fundingTxFetcher from './tasks/lightning/sync-tasks/funding-tx-fetcher';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Server {
 | 
					class Server {
 | 
				
			||||||
  private wss: WebSocket.Server | undefined;
 | 
					  private wss: WebSocket.Server | undefined;
 | 
				
			||||||
@ -74,7 +74,7 @@ class Server {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async startServer(worker = false) {
 | 
					  async startServer(worker = false): Promise<void> {
 | 
				
			||||||
    logger.notice(`Starting Mempool Server${worker ? ' (worker)' : ''}... (${backendInfo.getShortCommitHash()})`);
 | 
					    logger.notice(`Starting Mempool Server${worker ? ' (worker)' : ''}... (${backendInfo.getShortCommitHash()})`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.app
 | 
					    this.app
 | 
				
			||||||
@ -92,7 +92,9 @@ class Server {
 | 
				
			|||||||
    this.setUpWebsocketHandling();
 | 
					    this.setUpWebsocketHandling();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await syncAssets.syncAssets$();
 | 
					    await syncAssets.syncAssets$();
 | 
				
			||||||
    diskCache.loadMempoolCache();
 | 
					    if (config.MEMPOOL.ENABLED) {
 | 
				
			||||||
 | 
					      diskCache.loadMempoolCache();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (config.DATABASE.ENABLED) {
 | 
					    if (config.DATABASE.ENABLED) {
 | 
				
			||||||
      await DB.checkDbConnection();
 | 
					      await DB.checkDbConnection();
 | 
				
			||||||
@ -127,7 +129,10 @@ class Server {
 | 
				
			|||||||
    fiatConversion.startService();
 | 
					    fiatConversion.startService();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.setUpHttpApiRoutes();
 | 
					    this.setUpHttpApiRoutes();
 | 
				
			||||||
    this.runMainUpdateLoop();
 | 
					
 | 
				
			||||||
 | 
					    if (config.MEMPOOL.ENABLED) {
 | 
				
			||||||
 | 
					      this.runMainUpdateLoop();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (config.BISQ.ENABLED) {
 | 
					    if (config.BISQ.ENABLED) {
 | 
				
			||||||
      bisq.startBisqService();
 | 
					      bisq.startBisqService();
 | 
				
			||||||
@ -149,7 +154,7 @@ class Server {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async runMainUpdateLoop() {
 | 
					  async runMainUpdateLoop(): Promise<void> {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
        await memPool.$updateMemPoolInfo();
 | 
					        await memPool.$updateMemPoolInfo();
 | 
				
			||||||
@ -183,7 +188,7 @@ class Server {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async $runLightningBackend() {
 | 
					  async $runLightningBackend(): Promise<void> {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      await fundingTxFetcher.$init();
 | 
					      await fundingTxFetcher.$init();
 | 
				
			||||||
      await networkSyncService.$startService();
 | 
					      await networkSyncService.$startService();
 | 
				
			||||||
@ -195,7 +200,7 @@ class Server {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setUpWebsocketHandling() {
 | 
					  setUpWebsocketHandling(): void {
 | 
				
			||||||
    if (this.wss) {
 | 
					    if (this.wss) {
 | 
				
			||||||
      websocketHandler.setWebsocketServer(this.wss);
 | 
					      websocketHandler.setWebsocketServer(this.wss);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -209,19 +214,21 @@ class Server {
 | 
				
			|||||||
      });
 | 
					      });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    websocketHandler.setupConnectionHandling();
 | 
					    websocketHandler.setupConnectionHandling();
 | 
				
			||||||
    statistics.setNewStatisticsEntryCallback(websocketHandler.handleNewStatistic.bind(websocketHandler));
 | 
					    if (config.MEMPOOL.ENABLED) {
 | 
				
			||||||
    blocks.setNewBlockCallback(websocketHandler.handleNewBlock.bind(websocketHandler));
 | 
					      statistics.setNewStatisticsEntryCallback(websocketHandler.handleNewStatistic.bind(websocketHandler));
 | 
				
			||||||
    memPool.setMempoolChangedCallback(websocketHandler.handleMempoolChange.bind(websocketHandler));
 | 
					      blocks.setNewBlockCallback(websocketHandler.handleNewBlock.bind(websocketHandler));
 | 
				
			||||||
 | 
					      memPool.setMempoolChangedCallback(websocketHandler.handleMempoolChange.bind(websocketHandler));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    fiatConversion.setProgressChangedCallback(websocketHandler.handleNewConversionRates.bind(websocketHandler));
 | 
					    fiatConversion.setProgressChangedCallback(websocketHandler.handleNewConversionRates.bind(websocketHandler));
 | 
				
			||||||
    loadingIndicators.setProgressChangedCallback(websocketHandler.handleLoadingChanged.bind(websocketHandler));
 | 
					    loadingIndicators.setProgressChangedCallback(websocketHandler.handleLoadingChanged.bind(websocketHandler));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  setUpHttpApiRoutes() {
 | 
					  setUpHttpApiRoutes(): void {
 | 
				
			||||||
    bitcoinRoutes.initRoutes(this.app);
 | 
					    bitcoinRoutes.initRoutes(this.app);
 | 
				
			||||||
    if (config.STATISTICS.ENABLED && config.DATABASE.ENABLED) {
 | 
					    if (config.STATISTICS.ENABLED && config.DATABASE.ENABLED && config.MEMPOOL.ENABLED) {
 | 
				
			||||||
      statisticsRoutes.initRoutes(this.app);
 | 
					      statisticsRoutes.initRoutes(this.app);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (Common.indexingEnabled()) {
 | 
					    if (Common.indexingEnabled() && config.MEMPOOL.ENABLED) {
 | 
				
			||||||
      miningRoutes.initRoutes(this.app);
 | 
					      miningRoutes.initRoutes(this.app);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (config.BISQ.ENABLED) {
 | 
					    if (config.BISQ.ENABLED) {
 | 
				
			||||||
@ -238,4 +245,4 @@ class Server {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const server = new Server();
 | 
					((): Server => new Server())();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user