diff --git a/backend/src/repositories/HashratesRepository.ts b/backend/src/repositories/HashratesRepository.ts index 8388b9122..338948427 100644 --- a/backend/src/repositories/HashratesRepository.ts +++ b/backend/src/repositories/HashratesRepository.ts @@ -102,7 +102,7 @@ class HashratesRepository { /** * Returns a pool hashrate history */ - public async $getPoolWeeklyHashrate(slug: string): Promise { + public async $getPoolWeeklyHashrate(slug: string): Promise { const pool = await PoolsRepository.$getPool(slug); if (!pool) { throw new Error(`This mining pool does not exist`); diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 3722a6c64..db5b4f05f 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -575,8 +575,10 @@ class Routes { public async $getPools(interval: string, req: Request, res: Response) { try { const stats = await miningStats.$getPoolsStats(interval); + 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(stats); } catch (e) { @@ -587,14 +589,12 @@ class Routes { public async $getPoolsHistoricalHashrate(req: Request, res: Response) { try { const hashrates = await HashratesRepository.$getPoolsWeeklyHashrate(req.params.interval ?? null); - const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp(); + 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 * 300).toUTCString()); - res.json({ - oldestIndexedBlockTimestamp: oldestIndexedBlockTimestamp, - hashrates: hashrates, - }); + res.json(hashrates); } catch (e) { res.status(500).send(e instanceof Error ? e.message : e); } @@ -603,14 +603,12 @@ class Routes { public async $getPoolHistoricalHashrate(req: Request, res: Response) { try { const hashrates = await HashratesRepository.$getPoolWeeklyHashrate(req.params.slug); - const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp(); + 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 * 300).toUTCString()); - res.json({ - oldestIndexedBlockTimestamp: oldestIndexedBlockTimestamp, - hashrates: hashrates, - }); + res.json(hashrates); } catch (e) { if (e instanceof Error && e.message.indexOf('This mining pool does not exist') > -1) { res.status(404).send(e.message); @@ -624,12 +622,12 @@ class Routes { try { const hashrates = await HashratesRepository.$getNetworkDailyHashrate(req.params.interval ?? null); const difficulty = await BlocksRepository.$getBlocksDifficulty(req.params.interval ?? null); - const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp(); + 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 * 300).toUTCString()); res.json({ - oldestIndexedBlockTimestamp: oldestIndexedBlockTimestamp, hashrates: hashrates, difficulty: difficulty, }); @@ -641,14 +639,12 @@ class Routes { public async $getHistoricalBlockFees(req: Request, res: Response) { try { const blockFees = await mining.$getHistoricalBlockFees(req.params.interval ?? null); - const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp(); + 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 * 300).toUTCString()); - res.json({ - oldestIndexedBlockTimestamp: oldestIndexedBlockTimestamp, - blockFees: blockFees, - }); + res.json(blockFees); } catch (e) { res.status(500).send(e instanceof Error ? e.message : e); } @@ -657,14 +653,12 @@ class Routes { public async $getHistoricalBlockRewards(req: Request, res: Response) { try { const blockRewards = await mining.$getHistoricalBlockRewards(req.params.interval ?? null); - const oldestIndexedBlockTimestamp = await BlocksRepository.$oldestBlockTimestamp(); + 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 * 300).toUTCString()); - res.json({ - oldestIndexedBlockTimestamp: oldestIndexedBlockTimestamp, - blockRewards: blockRewards, - }); + res.json(blockRewards); } catch (e) { res.status(500).send(e instanceof Error ? e.message : e); } @@ -986,7 +980,7 @@ class Routes { public async $getRewardStats(req: Request, res: Response) { try { - const response = await mining.$getRewardStats(parseInt(req.params.blockCount)) + const response = await mining.$getRewardStats(parseInt(req.params.blockCount, 10)); res.json(response); } catch (e) { res.status(500).end(); diff --git a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.html b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.html index 605004820..eaf30ef17 100644 --- a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.html +++ b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.html @@ -3,34 +3,34 @@ Block fees
-
diff --git a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts index 488634cc7..e6aeaa61c 100644 --- a/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts +++ b/frontend/src/app/components/block-fees-graph/block-fees-graph.component.ts @@ -68,19 +68,15 @@ export class BlockFeesGraphComponent implements OnInit { this.isLoading = true; return this.apiService.getHistoricalBlockFees$(timespan) .pipe( - tap((data: any) => { + tap((response) => { this.prepareChartOptions({ - blockFees: data.blockFees.map(val => [val.timestamp * 1000, val.avg_fees / 100000000]), + blockFees: response.body.map(val => [val.timestamp * 1000, val.avg_fees / 100000000]), }); this.isLoading = false; }), - map((data: any) => { - const availableTimespanDay = ( - (new Date().getTime() / 1000) - (data.oldestIndexedBlockTimestamp) - ) / 3600 / 24; - + map((response) => { return { - availableTimespanDay: availableTimespanDay, + blockCount: parseInt(response.headers.get('x-total-count'), 10), }; }), ); diff --git a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.html b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.html index 32baafc45..922439e41 100644 --- a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.html +++ b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.html @@ -4,34 +4,34 @@ Block rewards
-
diff --git a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts index fd1f6a680..f525c0c4b 100644 --- a/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts +++ b/frontend/src/app/components/block-rewards-graph/block-rewards-graph.component.ts @@ -66,19 +66,15 @@ export class BlockRewardsGraphComponent implements OnInit { this.isLoading = true; return this.apiService.getHistoricalBlockRewards$(timespan) .pipe( - tap((data: any) => { + tap((response) => { this.prepareChartOptions({ - blockRewards: data.blockRewards.map(val => [val.timestamp * 1000, val.avg_rewards / 100000000]), + blockRewards: response.body.map(val => [val.timestamp * 1000, val.avg_rewards / 100000000]), }); this.isLoading = false; }), - map((data: any) => { - const availableTimespanDay = ( - (new Date().getTime() / 1000) - (data.oldestIndexedBlockTimestamp) - ) / 3600 / 24; - + map((response) => { return { - availableTimespanDay: availableTimespanDay, + blockCount: parseInt(response.headers.get('x-total-count'), 10), }; }), ); diff --git a/frontend/src/app/components/difficulty-adjustments-table/difficulty-adjustments-table.components.ts b/frontend/src/app/components/difficulty-adjustments-table/difficulty-adjustments-table.components.ts index 5e8b3ded7..1026bc145 100644 --- a/frontend/src/app/components/difficulty-adjustments-table/difficulty-adjustments-table.components.ts +++ b/frontend/src/app/components/difficulty-adjustments-table/difficulty-adjustments-table.components.ts @@ -32,7 +32,8 @@ export class DifficultyAdjustmentsTable implements OnInit { ngOnInit(): void { this.hashrateObservable$ = this.apiService.getHistoricalHashrate$('1y') .pipe( - map((data: any) => { + map((response) => { + const data = response.body; const availableTimespanDay = ( (new Date().getTime() / 1000) - (data.oldestIndexedBlockTimestamp) ) / 3600 / 24; diff --git a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.html b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.html index 93f17dcdf..b01a68dc4 100644 --- a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.html +++ b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.html @@ -22,25 +22,25 @@ Hashrate & Difficulty
-
diff --git a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts index 737323a7c..2a8419c24 100644 --- a/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts +++ b/frontend/src/app/components/hashrate-chart/hashrate-chart.component.ts @@ -79,7 +79,8 @@ export class HashrateChartComponent implements OnInit { this.isLoading = true; return this.apiService.getHistoricalHashrate$(timespan) .pipe( - tap((data: any) => { + tap((response) => { + const data = response.body; // We generate duplicated data point so the tooltip works nicely const diffFixed = []; let diffIndex = 1; @@ -111,7 +112,6 @@ export class HashrateChartComponent implements OnInit { this.prepareChartOptions({ hashrates: data.hashrates.map(val => [val.timestamp * 1000, val.avgHashrate]), difficulty: diffFixed.map(val => [val.timestamp * 1000, val.difficulty]), - timestamp: data.oldestIndexedBlockTimestamp, }); this.isLoading = false; @@ -120,13 +120,10 @@ export class HashrateChartComponent implements OnInit { throw new Error(); } }), - map((data: any) => { - const availableTimespanDay = ( - (new Date().getTime() / 1000) - (data.oldestIndexedBlockTimestamp) - ) / 3600 / 24; - + map((response) => { + const data = response.body; return { - availableTimespanDay: availableTimespanDay, + blockCount: parseInt(response.headers.get('x-total-count'), 10), currentDifficulty: Math.round(data.difficulty[data.difficulty.length - 1].difficulty * 100) / 100, currentHashrate: data.hashrates[data.hashrates.length - 1].avgHashrate, }; diff --git a/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.html b/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.html index f3d547dd6..97f6c5164 100644 --- a/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.html +++ b/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.html @@ -4,25 +4,25 @@ Mining pools dominance
-
diff --git a/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.ts b/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.ts index 85bea9840..e974b20aa 100644 --- a/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.ts +++ b/frontend/src/app/components/hashrates-chart-pools/hashrate-chart-pools.component.ts @@ -72,10 +72,11 @@ export class HashrateChartPoolsComponent implements OnInit { this.isLoading = true; return this.apiService.getHistoricalPoolsHashrate$(timespan) .pipe( - tap((data: any) => { + tap((response) => { + const hashrates = response.body; // Prepare series (group all hashrates data point by pool) const grouped = {}; - for (const hashrate of data.hashrates) { + for (const hashrate of hashrates) { if (!grouped.hasOwnProperty(hashrate.poolName)) { grouped[hashrate.poolName] = []; } @@ -119,7 +120,6 @@ export class HashrateChartPoolsComponent implements OnInit { this.prepareChartOptions({ legends: legends, series: series, - timestamp: data.oldestIndexedBlockTimestamp, }); this.isLoading = false; @@ -128,13 +128,10 @@ export class HashrateChartPoolsComponent implements OnInit { throw new Error(); } }), - map((data: any) => { - const availableTimespanDay = ( - (new Date().getTime() / 1000) - (data.oldestIndexedBlockTimestamp) - ) / 3600 / 24; + map((response) => { return { - availableTimespanDay: availableTimespanDay, - }; + blockCount: parseInt(response.headers.get('x-total-count'), 10), + } }), retryWhen((errors) => errors.pipe( delay(60000) diff --git a/frontend/src/app/components/pool-ranking/pool-ranking.component.html b/frontend/src/app/components/pool-ranking/pool-ranking.component.html index 3c038df80..9a9fe45bd 100644 --- a/frontend/src/app/components/pool-ranking/pool-ranking.component.html +++ b/frontend/src/app/components/pool-ranking/pool-ranking.component.html @@ -26,36 +26,36 @@
Mining pools share + *ngIf="!widget && (miningStatsObservable$ | async) as stats">
-
diff --git a/frontend/src/app/components/pool-ranking/pool-ranking.component.ts b/frontend/src/app/components/pool-ranking/pool-ranking.component.ts index 95c2be2b7..4056b0ed6 100644 --- a/frontend/src/app/components/pool-ranking/pool-ranking.component.ts +++ b/frontend/src/app/components/pool-ranking/pool-ranking.component.ts @@ -276,7 +276,7 @@ export class PoolRankingComponent implements OnInit { totalEmptyBlock: 0, totalEmptyBlockRatio: '', pools: [], - availableTimespanDay: 0, + totalBlockCount: 0, miningUnits: { hashrateDivider: 1, hashrateUnit: '', diff --git a/frontend/src/app/components/pool/pool.component.ts b/frontend/src/app/components/pool/pool.component.ts index 4d41c2437..9d644121a 100644 --- a/frontend/src/app/components/pool/pool.component.ts +++ b/frontend/src/app/components/pool/pool.component.ts @@ -56,7 +56,7 @@ export class PoolComponent implements OnInit { .pipe( switchMap((data) => { this.isLoading = false; - this.prepareChartOptions(data.hashrates.map(val => [val.timestamp * 1000, val.avgHashrate])); + this.prepareChartOptions(data.map(val => [val.timestamp * 1000, val.avgHashrate])); return [slug]; }), ); diff --git a/frontend/src/app/services/api.service.ts b/frontend/src/app/services/api.service.ts index 133292837..b892e16ff 100644 --- a/frontend/src/app/services/api.service.ts +++ b/frontend/src/app/services/api.service.ts @@ -125,10 +125,10 @@ export class ApiService { return this.httpClient.post(this.apiBaseUrl + this.apiBasePath + '/api/tx', hexPayload, { responseType: 'text' as 'json'}); } - listPools$(interval: string | undefined) : Observable { - return this.httpClient.get( + listPools$(interval: string | undefined) : Observable { + return this.httpClient.get( this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/pools` + - (interval !== undefined ? `/${interval}` : '') + (interval !== undefined ? `/${interval}` : ''), { observe: 'response' } ); } @@ -157,28 +157,28 @@ export class ApiService { getHistoricalHashrate$(interval: string | undefined): Observable { return this.httpClient.get( this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/hashrate` + - (interval !== undefined ? `/${interval}` : '') + (interval !== undefined ? `/${interval}` : ''), { observe: 'response' } ); } getHistoricalPoolsHashrate$(interval: string | undefined): Observable { return this.httpClient.get( this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/hashrate/pools` + - (interval !== undefined ? `/${interval}` : '') + (interval !== undefined ? `/${interval}` : ''), { observe: 'response' } ); } getHistoricalBlockFees$(interval: string | undefined) : Observable { return this.httpClient.get( this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/blocks/fees` + - (interval !== undefined ? `/${interval}` : '') + (interval !== undefined ? `/${interval}` : ''), { observe: 'response' } ); } getHistoricalBlockRewards$(interval: string | undefined) : Observable { return this.httpClient.get( this.apiBaseUrl + this.apiBasePath + `/api/v1/mining/blocks/rewards` + - (interval !== undefined ? `/${interval}` : '') + (interval !== undefined ? `/${interval}` : ''), { observe: 'response' } ); } diff --git a/frontend/src/app/services/mining.service.ts b/frontend/src/app/services/mining.service.ts index 0480b09cd..7806debd7 100644 --- a/frontend/src/app/services/mining.service.ts +++ b/frontend/src/app/services/mining.service.ts @@ -18,7 +18,7 @@ export interface MiningStats { totalEmptyBlockRatio: string; pools: SinglePoolStats[]; miningUnits: MiningUnits; - availableTimespanDay: number; + totalBlockCount: number; } @Injectable({ @@ -37,7 +37,7 @@ export class MiningService { */ public getMiningStats(interval: string): Observable { return this.apiService.listPools$(interval).pipe( - map(pools => this.generateMiningStats(pools)) + map(response => this.generateMiningStats(response)) ); } @@ -82,7 +82,8 @@ export class MiningService { return preference; } - private generateMiningStats(stats: PoolsStats): MiningStats { + private generateMiningStats(response): MiningStats { + const stats: PoolsStats = response.body; const miningUnits = this.getMiningUnits(); const hashrateDivider = miningUnits.hashrateDivider; @@ -100,10 +101,6 @@ export class MiningService { }; }); - const availableTimespanDay = ( - (new Date().getTime() / 1000) - (stats.oldestIndexedBlockTimestamp) - ) / 3600 / 24; - return { lastEstimatedHashrate: (stats.lastEstimatedHashrate / hashrateDivider).toFixed(2), blockCount: stats.blockCount, @@ -111,7 +108,7 @@ export class MiningService { totalEmptyBlockRatio: totalEmptyBlockRatio, pools: poolsStats, miningUnits: miningUnits, - availableTimespanDay: availableTimespanDay, + totalBlockCount: parseInt(response.headers.get('x-total-count'), 10), }; } }