diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index 018c78c4b..090514e5c 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -55,7 +55,7 @@ class Blocks { const transactions: TransactionExtended[] = []; - for (let i = 1; i < txIds.length; i++) { + for (let i = 0; i < txIds.length; i++) { if (mempool[txIds[i]]) { transactions.push(mempool[txIds[i]]); found++; @@ -71,6 +71,7 @@ class Blocks { console.log(`${found} of ${txIds.length} found in mempool. ${notFound} not found.`); + block.reward = transactions[0].vout.reduce((acc, curr) => acc + curr.value, 0); transactions.sort((a, b) => b.feePerVsize - a.feePerVsize); block.medianFee = transactions.length ? this.median(transactions.map((tx) => tx.feePerVsize)) : 0; block.feeRange = transactions.length ? this.getFeesInRange(transactions, 8) : [0, 0]; diff --git a/backend/src/interfaces.ts b/backend/src/interfaces.ts index 1851a823d..95e28adeb 100644 --- a/backend/src/interfaces.ts +++ b/backend/src/interfaces.ts @@ -87,6 +87,7 @@ export interface Block { medianFee?: number; feeRange?: number[]; + reward?: number; } export interface Address { diff --git a/frontend/src/app/components/block/block.component.html b/frontend/src/app/components/block/block.component.html index 35ec83c37..02f669dc2 100644 --- a/frontend/src/app/components/block/block.component.html +++ b/frontend/src/app/components/block/block.component.html @@ -47,14 +47,28 @@ Previous Block {{ block.previousblockhash | shortenString : 32 }} - - Block subsidy - {{ blockSubsidy | number: '1.2-2' }} BTC () - - - Status - {{ (latestBlock.height - block.height + 1) }} confirmation{{ (latestBlock.height - block.height + 1) === 1 ? '' : 's' }} - + + + Total fees + {{ fees | number: '1.2-8' }} BTC () + + + Reward + fees: + + {{ blockSubsidy + fees | number: '1.2-8' }} BTC () + + + + + + Total fees + + + + Reward + fees: + + + diff --git a/frontend/src/app/components/block/block.component.ts b/frontend/src/app/components/block/block.component.ts index 65f5363a0..f8c41a08e 100644 --- a/frontend/src/app/components/block/block.component.ts +++ b/frontend/src/app/components/block/block.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, ParamMap } from '@angular/router'; import { ElectrsApiService } from '../../services/electrs-api.service'; import { switchMap } from 'rxjs/operators'; -import { Block, Transaction } from '../../interfaces/electrs.interface'; +import { Block, Transaction, Vout } from '../../interfaces/electrs.interface'; import { of } from 'rxjs'; import { StateService } from '../../services/state.service'; import { WebsocketService } from 'src/app/services/websocket.service'; @@ -21,7 +21,8 @@ export class BlockComponent implements OnInit { transactions: Transaction[]; isLoadingTransactions = true; error: any; - blockSubsidy = 50; + blockSubsidy: number; + fees: number; constructor( private route: ActivatedRoute, @@ -37,6 +38,7 @@ export class BlockComponent implements OnInit { switchMap((params: ParamMap) => { const blockHash: string = params.get('id') || ''; this.error = undefined; + this.fees = undefined; if (history.state.data && history.state.data.blockHeight) { this.blockHeight = history.state.data.blockHeight; @@ -59,6 +61,9 @@ export class BlockComponent implements OnInit { this.blockHeight = block.height; this.isLoadingBlock = false; this.setBlockSubsidy(); + if (block.reward) { + this.fees = block.reward / 100000000; + } this.getBlockTransactions(block.id); }, (error) => { @@ -71,6 +76,7 @@ export class BlockComponent implements OnInit { } setBlockSubsidy() { + this.blockSubsidy = 50; let halvenings = Math.floor(this.block.height / 210000); while (halvenings > 0) { this.blockSubsidy = this.blockSubsidy / 2; @@ -83,6 +89,9 @@ export class BlockComponent implements OnInit { this.transactions = null; this.electrsApiService.getBlockTransactions$(hash) .subscribe((transactions: any) => { + if (!this.fees) { + this.fees = transactions[0].vout.reduce((acc: number, curr: Vout) => acc + curr.value, 0) / 100000000 - this.blockSubsidy; + } this.transactions = transactions; this.isLoadingTransactions = false; }); diff --git a/frontend/src/app/interfaces/electrs.interface.ts b/frontend/src/app/interfaces/electrs.interface.ts index 3b0230cd3..5f52d75cb 100644 --- a/frontend/src/app/interfaces/electrs.interface.ts +++ b/frontend/src/app/interfaces/electrs.interface.ts @@ -67,6 +67,7 @@ export interface Block { medianFee?: number; feeRange?: number[]; + reward?: number; } export interface Address {