Add block fees vs subsidy bar chart

This commit is contained in:
natsoni
2024-05-03 12:33:05 +02:00
parent 1b25a71d9f
commit 453a2224cd
10 changed files with 630 additions and 0 deletions

View File

@@ -24,6 +24,8 @@ 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)
@@ -217,6 +219,25 @@ 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);

View File

@@ -50,6 +50,13 @@ 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
*/