mempool/backend/src/api/fee-api.ts

36 lines
916 B
TypeScript
Raw Normal View History

const config = require('../../mempool-config.json');
import projectedBlocks from './mempool-blocks';
2019-07-21 16:59:47 +02:00
class FeeApi {
constructor() { }
defaultFee = config.LIQUID ? 0.1 : 1;
2019-07-21 16:59:47 +02:00
public getRecommendedFee() {
const pBlocks = projectedBlocks.getMempoolBlocks();
2019-07-21 16:59:47 +02:00
if (!pBlocks.length) {
return {
'fastestFee': 0,
'halfHourFee': 0,
'hourFee': 0,
};
}
let firstMedianFee = Math.ceil(pBlocks[0].medianFee);
if (pBlocks.length === 1 && pBlocks[0].blockVSize <= 500000) {
firstMedianFee = this.defaultFee;
2019-07-21 16:59:47 +02:00
}
const secondMedianFee = pBlocks[1] ? Math.ceil(pBlocks[1].medianFee) : this.defaultFee;
const thirdMedianFee = pBlocks[2] ? Math.ceil(pBlocks[2].medianFee) : this.defaultFee;
2019-07-21 16:59:47 +02:00
return {
'fastestFee': firstMedianFee,
'halfHourFee': secondMedianFee,
'hourFee': thirdMedianFee,
};
}
}
export default new FeeApi();