2019-07-21 16:59:47 +02:00
|
|
|
import statistics from './api/statistics';
|
|
|
|
import feeApi from './api/fee-api';
|
2020-02-16 16:15:07 +01:00
|
|
|
import mempoolBlocks from './api/mempool-blocks';
|
2019-07-21 16:59:47 +02:00
|
|
|
|
|
|
|
class Routes {
|
2019-08-15 13:06:08 +02:00
|
|
|
private cache = {};
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.createCache();
|
2019-08-19 09:31:14 +02:00
|
|
|
setInterval(this.createCache.bind(this), 600000);
|
2019-08-15 13:06:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private async createCache() {
|
|
|
|
this.cache['24h'] = await statistics.$list24H();
|
|
|
|
this.cache['1w'] = await statistics.$list1W();
|
|
|
|
this.cache['1m'] = await statistics.$list1M();
|
|
|
|
this.cache['3m'] = await statistics.$list3M();
|
|
|
|
this.cache['6m'] = await statistics.$list6M();
|
2020-02-16 18:26:57 +01:00
|
|
|
this.cache['1y'] = await statistics.$list1Y();
|
2019-08-15 13:06:08 +02:00
|
|
|
console.log('Statistics cache created');
|
|
|
|
}
|
2019-07-21 16:59:47 +02:00
|
|
|
|
|
|
|
public async get2HStatistics(req, res) {
|
|
|
|
const result = await statistics.$list2H();
|
|
|
|
res.send(result);
|
|
|
|
}
|
|
|
|
|
2019-08-15 13:06:08 +02:00
|
|
|
public get24HStatistics(req, res) {
|
|
|
|
res.send(this.cache['24h']);
|
2019-07-21 16:59:47 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 13:06:08 +02:00
|
|
|
public get1WHStatistics(req, res) {
|
|
|
|
res.send(this.cache['1w']);
|
2019-07-21 16:59:47 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 13:06:08 +02:00
|
|
|
public get1MStatistics(req, res) {
|
|
|
|
res.send(this.cache['1m']);
|
2019-07-21 16:59:47 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 13:06:08 +02:00
|
|
|
public get3MStatistics(req, res) {
|
|
|
|
res.send(this.cache['3m']);
|
2019-07-21 16:59:47 +02:00
|
|
|
}
|
|
|
|
|
2019-08-15 13:06:08 +02:00
|
|
|
public get6MStatistics(req, res) {
|
|
|
|
res.send(this.cache['6m']);
|
2019-07-21 16:59:47 +02:00
|
|
|
}
|
|
|
|
|
2020-02-16 18:26:57 +01:00
|
|
|
public get1YStatistics(req, res) {
|
|
|
|
res.send(this.cache['1y']);
|
|
|
|
}
|
|
|
|
|
2019-07-21 16:59:47 +02:00
|
|
|
public async getRecommendedFees(req, res) {
|
|
|
|
const result = feeApi.getRecommendedFee();
|
|
|
|
res.send(result);
|
|
|
|
}
|
|
|
|
|
2020-02-16 16:15:07 +01:00
|
|
|
public async getMempoolBlocks(req, res) {
|
2019-11-06 08:35:02 +01:00
|
|
|
try {
|
2020-02-16 16:15:07 +01:00
|
|
|
const result = await mempoolBlocks.getMempoolBlocks();
|
2019-11-06 08:35:02 +01:00
|
|
|
res.send(result);
|
|
|
|
} catch (e) {
|
|
|
|
res.status(500).send(e.message);
|
|
|
|
}
|
|
|
|
}
|
2019-07-21 16:59:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new Routes();
|