Block subsidy graph back to timespan selection mode
This commit is contained in:
@@ -24,8 +24,6 @@ class MiningRoutes {
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/difficulty-adjustments', this.$getDifficultyAdjustments)
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/reward-stats/:blockCount', this.$getRewardStats)
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/fees/:interval', this.$getHistoricalBlockFees)
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/exact-fees/:height', this.$getHistoricalExactBlockFees)
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/exact-fees', this.$getHistoricalExactBlockFees)
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/rewards/:interval', this.$getHistoricalBlockRewards)
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/fee-rates/:interval', this.$getHistoricalBlockFeeRates)
|
||||
.get(config.MEMPOOL.API_URL_PREFIX + 'mining/blocks/sizes-weights/:interval', this.$getHistoricalBlockSizeAndWeight)
|
||||
@@ -219,25 +217,6 @@ class MiningRoutes {
|
||||
}
|
||||
}
|
||||
|
||||
private async $getHistoricalExactBlockFees(req: Request, res: Response) {
|
||||
try {
|
||||
const heightRegex = /^(0|[1-9]\d{0,9})$/;
|
||||
if (req.params.height !== undefined && !heightRegex.test(req.params.height)) {
|
||||
throw new Error('Invalid height parameter');
|
||||
}
|
||||
|
||||
const blockFees = await mining.$getHistoricalExactBlockFees(req.params.height);
|
||||
const blockCount = await BlocksRepository.$blockCount(null, null);
|
||||
res.header('Pragma', 'public');
|
||||
res.header('Cache-control', 'public');
|
||||
res.header('X-total-count', blockCount.toString());
|
||||
res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString());
|
||||
res.json(blockFees);
|
||||
} catch (e) {
|
||||
res.status(500).send(e instanceof Error ? e.message : e);
|
||||
}
|
||||
}
|
||||
|
||||
private async $getHistoricalBlockRewards(req: Request, res: Response) {
|
||||
try {
|
||||
const blockRewards = await mining.$getHistoricalBlockRewards(req.params.interval);
|
||||
|
||||
@@ -50,13 +50,6 @@ class Mining {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get historical (not averaged) block total fee
|
||||
*/
|
||||
public async $getHistoricalExactBlockFees(height: string | null = null): Promise<any> {
|
||||
return await BlocksRepository.$getHistoricalExactBlockFees(height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get historical block rewards
|
||||
*/
|
||||
|
||||
@@ -689,52 +689,6 @@ class BlocksRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the historical block fees
|
||||
*/
|
||||
public async $getHistoricalExactBlockFees(height: string | null): Promise<any> {
|
||||
try {
|
||||
let query = `SELECT
|
||||
blocks.height,
|
||||
fees,
|
||||
prices.USD
|
||||
FROM blocks
|
||||
JOIN blocks_prices on blocks_prices.height = blocks.height
|
||||
JOIN prices on prices.id = blocks_prices.price_id
|
||||
`;
|
||||
|
||||
if (height !== null) {
|
||||
query += ` WHERE blocks.height <= ${height}`;
|
||||
}
|
||||
query += ` ORDER BY blocks.height DESC LIMIT 10000`;
|
||||
|
||||
const [rows]: any = await DB.query(query);
|
||||
|
||||
// Add accelerations data if available
|
||||
if (config.MEMPOOL_SERVICES.ACCELERATIONS && rows.length > 0) {
|
||||
|
||||
let query = `
|
||||
SELECT height, boost_cost FROM accelerations
|
||||
WHERE height >= ${rows[rows.length - 1].height} AND height <= ${rows[0].height}
|
||||
`;
|
||||
const [accelerations]: any = await DB.query(query);
|
||||
|
||||
for (let i = 0; i < accelerations.length; ++i) {
|
||||
const idx = rows.findIndex((block) => block.height === accelerations[i].height);
|
||||
if (idx !== -1) {
|
||||
if (rows[idx].accelerations === undefined) rows[idx].accelerations = 0;
|
||||
rows[idx].accelerations += accelerations[i].boost_cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rows;
|
||||
} catch (e) {
|
||||
logger.err('Cannot generate exact block fees history. Reason: ' + (e instanceof Error ? e.message : e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the historical averaged block rewards
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user