2020-09-27 13:12:36 +02:00
|
|
|
const config = require('../../mempool-config.json');
|
2020-02-16 16:15:07 +01:00
|
|
|
import projectedBlocks from './mempool-blocks';
|
2019-07-21 16:59:47 +02:00
|
|
|
|
|
|
|
class FeeApi {
|
|
|
|
constructor() { }
|
|
|
|
|
2020-09-27 13:12:36 +02:00
|
|
|
defaultFee = config.LIQUID ? 0.1 : 1;
|
|
|
|
|
2019-07-21 16:59:47 +02:00
|
|
|
public getRecommendedFee() {
|
2020-02-16 16:15:07 +01:00
|
|
|
const pBlocks = projectedBlocks.getMempoolBlocks();
|
2019-07-21 16:59:47 +02:00
|
|
|
if (!pBlocks.length) {
|
|
|
|
return {
|
2020-09-28 11:32:48 +02:00
|
|
|
'fastestFee': this.defaultFee,
|
|
|
|
'halfHourFee': this.defaultFee,
|
|
|
|
'hourFee': this.defaultFee,
|
2019-07-21 16:59:47 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
let firstMedianFee = Math.ceil(pBlocks[0].medianFee);
|
|
|
|
|
2020-02-16 16:15:07 +01:00
|
|
|
if (pBlocks.length === 1 && pBlocks[0].blockVSize <= 500000) {
|
2020-09-27 13:12:36 +02:00
|
|
|
firstMedianFee = this.defaultFee;
|
2019-07-21 16:59:47 +02:00
|
|
|
}
|
|
|
|
|
2020-09-27 13:12:36 +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();
|