@@ -4,7 +4,7 @@ import * as request from 'request';
|
||||
import { BisqBlocks, BisqBlock, BisqTransaction, BisqStats, BisqTrade } from './interfaces';
|
||||
import { Common } from '../common';
|
||||
import { Block } from '../../interfaces';
|
||||
|
||||
import logger from '../../logger';
|
||||
class Bisq {
|
||||
private static BLOCKS_JSON_FILE_PATH = '/all/blocks.json';
|
||||
private latestBlockHeight = 0;
|
||||
@@ -38,7 +38,7 @@ class Bisq {
|
||||
|
||||
handleNewBitcoinBlock(block: Block): void {
|
||||
if (block.height - 2 > this.latestBlockHeight && this.latestBlockHeight !== 0) {
|
||||
console.log(`Bitcoin block height (#${block.height}) has diverged from the latest Bisq block height (#${this.latestBlockHeight}). Restarting watchers...`);
|
||||
logger.info(`Bitcoin block height (#${block.height}) has diverged from the latest Bisq block height (#${this.latestBlockHeight}). Restarting watchers...`);
|
||||
this.startTopDirectoryWatcher();
|
||||
this.startSubDirectoryWatcher();
|
||||
}
|
||||
@@ -82,7 +82,7 @@ class Bisq {
|
||||
|
||||
private checkForBisqDataFolder() {
|
||||
if (!fs.existsSync(config.BISQ_BLOCKS_DATA_PATH + Bisq.BLOCKS_JSON_FILE_PATH)) {
|
||||
console.log(config.BISQ_BLOCKS_DATA_PATH + Bisq.BLOCKS_JSON_FILE_PATH + ` doesn't exist. Make sure Bisq is running and the config is correct before starting the server.`);
|
||||
logger.info(config.BISQ_BLOCKS_DATA_PATH + Bisq.BLOCKS_JSON_FILE_PATH + ` doesn't exist. Make sure Bisq is running and the config is correct before starting the server.`);
|
||||
return process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class Bisq {
|
||||
this.subdirectoryWatcher.close();
|
||||
}
|
||||
fsWait = setTimeout(() => {
|
||||
console.log(`Bisq restart detected. Resetting both watchers in 3 minutes.`);
|
||||
logger.info(`Bisq restart detected. Resetting both watchers in 3 minutes.`);
|
||||
setTimeout(() => {
|
||||
this.startTopDirectoryWatcher();
|
||||
this.startSubDirectoryWatcher();
|
||||
@@ -115,7 +115,7 @@ class Bisq {
|
||||
this.subdirectoryWatcher.close();
|
||||
}
|
||||
if (!fs.existsSync(config.BISQ_BLOCKS_DATA_PATH + Bisq.BLOCKS_JSON_FILE_PATH)) {
|
||||
console.log(config.BISQ_BLOCKS_DATA_PATH + Bisq.BLOCKS_JSON_FILE_PATH + ` doesn't exist. Trying to restart sub directory watcher again in 3 minutes.`);
|
||||
logger.warn(config.BISQ_BLOCKS_DATA_PATH + Bisq.BLOCKS_JSON_FILE_PATH + ` doesn't exist. Trying to restart sub directory watcher again in 3 minutes.`);
|
||||
setTimeout(() => this.startSubDirectoryWatcher(), 180000);
|
||||
return;
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class Bisq {
|
||||
clearTimeout(fsWait);
|
||||
}
|
||||
fsWait = setTimeout(() => {
|
||||
console.log(`Change detected in the Bisq data folder.`);
|
||||
logger.info(`Change detected in the Bisq data folder.`);
|
||||
this.loadBisqDumpFile();
|
||||
}, 2000);
|
||||
});
|
||||
@@ -133,7 +133,7 @@ class Bisq {
|
||||
|
||||
private updatePrice() {
|
||||
request('https://markets.bisq.network/api/trades/?market=bsq_btc', { json: true }, (err, res, trades: BisqTrade[]) => {
|
||||
if (err) { return console.log(err); }
|
||||
if (err) { return logger.err(err); }
|
||||
|
||||
const prices: number[] = [];
|
||||
trades.forEach((trade) => {
|
||||
@@ -154,7 +154,7 @@ class Bisq {
|
||||
this.buildIndex();
|
||||
this.calculateStats();
|
||||
} catch (e) {
|
||||
console.log('loadBisqDumpFile() error.', e.message);
|
||||
logger.err('loadBisqDumpFile() error.' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ class Bisq {
|
||||
});
|
||||
|
||||
const time = new Date().getTime() - start;
|
||||
console.log('Bisq data index rebuilt in ' + time + ' ms');
|
||||
logger.info('Bisq data index rebuilt in ' + time + ' ms');
|
||||
}
|
||||
|
||||
private calculateStats() {
|
||||
@@ -236,14 +236,14 @@ class Bisq {
|
||||
private async loadBisqBlocksDump(cacheData: string): Promise<void> {
|
||||
const start = new Date().getTime();
|
||||
if (cacheData && cacheData.length !== 0) {
|
||||
console.log('Processing Bisq data dump...');
|
||||
logger.info('Processing Bisq data dump...');
|
||||
const data: BisqBlocks = JSON.parse(cacheData);
|
||||
if (data.blocks && data.blocks.length !== this.blocks.length) {
|
||||
this.blocks = data.blocks.filter((block) => block.txs.length > 0);
|
||||
this.blocks.reverse();
|
||||
this.latestBlockHeight = data.chainHeight;
|
||||
const time = new Date().getTime() - start;
|
||||
console.log('Bisq dump processed in ' + time + ' ms');
|
||||
logger.info('Bisq dump processed in ' + time + ' ms');
|
||||
} else {
|
||||
throw new Error(`Bisq dump didn't contain any blocks`);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ const config = require('../../../mempool-config.json');
|
||||
import * as fs from 'fs';
|
||||
import { OffersData as OffersData, TradesData, Currency } from './interfaces';
|
||||
import bisqMarket from './markets-api';
|
||||
import logger from '../../logger';
|
||||
|
||||
class Bisq {
|
||||
private static FOLDER_WATCH_CHANGE_DETECTION_DEBOUNCE = 4000;
|
||||
@@ -30,7 +31,7 @@ class Bisq {
|
||||
|
||||
private checkForBisqDataFolder() {
|
||||
if (!fs.existsSync(Bisq.MARKET_JSON_PATH + Bisq.MARKET_JSON_FILE_PATHS.cryptoCurrency)) {
|
||||
console.log(Bisq.MARKET_JSON_PATH + Bisq.MARKET_JSON_FILE_PATHS.cryptoCurrency + ` doesn't exist. Make sure Bisq is running and the config is correct before starting the server.`);
|
||||
logger.err(Bisq.MARKET_JSON_PATH + Bisq.MARKET_JSON_FILE_PATHS.cryptoCurrency + ` doesn't exist. Make sure Bisq is running and the config is correct before starting the server.`);
|
||||
return process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +41,7 @@ class Bisq {
|
||||
this.subdirectoryWatcher.close();
|
||||
}
|
||||
if (!fs.existsSync(Bisq.MARKET_JSON_PATH + Bisq.MARKET_JSON_FILE_PATHS.cryptoCurrency)) {
|
||||
console.log(Bisq.MARKET_JSON_PATH + Bisq.MARKET_JSON_FILE_PATHS.cryptoCurrency + ` doesn't exist. Trying to restart sub directory watcher again in 3 minutes.`);
|
||||
logger.warn(Bisq.MARKET_JSON_PATH + Bisq.MARKET_JSON_FILE_PATHS.cryptoCurrency + ` doesn't exist. Trying to restart sub directory watcher again in 3 minutes.`);
|
||||
setTimeout(() => this.startBisqDirectoryWatcher(), 180000);
|
||||
return;
|
||||
}
|
||||
@@ -50,7 +51,7 @@ class Bisq {
|
||||
clearTimeout(fsWait);
|
||||
}
|
||||
fsWait = setTimeout(() => {
|
||||
console.log(`Change detected in the Bisq market data folder.`);
|
||||
logger.info(`Change detected in the Bisq market data folder.`);
|
||||
this.loadBisqDumpFile();
|
||||
}, Bisq.FOLDER_WATCH_CHANGE_DETECTION_DEBOUNCE);
|
||||
});
|
||||
@@ -65,7 +66,7 @@ class Bisq {
|
||||
if (cryptoMtime > this.cryptoCurrencyLastMtime || fiatMtime > this.fiatCurrencyLastMtime) {
|
||||
const cryptoCurrencyData = await this.loadData<Currency[]>(Bisq.MARKET_JSON_FILE_PATHS.cryptoCurrency);
|
||||
const fiatCurrencyData = await this.loadData<Currency[]>(Bisq.MARKET_JSON_FILE_PATHS.fiatCurrency);
|
||||
console.log('Updating Bisq Market Currency Data');
|
||||
logger.info('Updating Bisq Market Currency Data');
|
||||
bisqMarket.setCurrencyData(cryptoCurrencyData, fiatCurrencyData);
|
||||
if (cryptoMtime > this.cryptoCurrencyLastMtime) {
|
||||
this.cryptoCurrencyLastMtime = cryptoMtime;
|
||||
@@ -78,7 +79,7 @@ class Bisq {
|
||||
const offersMtime = this.getFileMtime(Bisq.MARKET_JSON_FILE_PATHS.offers);
|
||||
if (offersMtime > this.offersLastMtime) {
|
||||
const offersData = await this.loadData<OffersData[]>(Bisq.MARKET_JSON_FILE_PATHS.offers);
|
||||
console.log('Updating Bisq Market Offers Data');
|
||||
logger.info('Updating Bisq Market Offers Data');
|
||||
bisqMarket.setOffersData(offersData);
|
||||
this.offersLastMtime = offersMtime;
|
||||
marketsDataUpdated = true;
|
||||
@@ -86,7 +87,7 @@ class Bisq {
|
||||
const tradesMtime = this.getFileMtime(Bisq.MARKET_JSON_FILE_PATHS.trades);
|
||||
if (tradesMtime > this.tradesLastMtime) {
|
||||
const tradesData = await this.loadData<TradesData[]>(Bisq.MARKET_JSON_FILE_PATHS.trades);
|
||||
console.log('Updating Bisq Market Trades Data');
|
||||
logger.info('Updating Bisq Market Trades Data');
|
||||
bisqMarket.setTradesData(tradesData);
|
||||
this.tradesLastMtime = tradesMtime;
|
||||
marketsDataUpdated = true;
|
||||
@@ -94,10 +95,10 @@ class Bisq {
|
||||
if (marketsDataUpdated) {
|
||||
bisqMarket.updateCache();
|
||||
const time = new Date().getTime() - start;
|
||||
console.log('Bisq market data updated in ' + time + ' ms');
|
||||
logger.info('Bisq market data updated in ' + time + ' ms');
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('loadBisqMarketDataDumpFile() error.', e.message);
|
||||
logger.err('loadBisqMarketDataDumpFile() error.' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user