mirror of
https://github.com/mempool/mempool.git
synced 2025-02-23 14:40:38 +01:00
Adding miner block reward and fee to block info.
This commit is contained in:
parent
f71ac67d24
commit
73e24195da
5 changed files with 37 additions and 11 deletions
|
@ -55,7 +55,7 @@ class Blocks {
|
||||||
|
|
||||||
const transactions: TransactionExtended[] = [];
|
const transactions: TransactionExtended[] = [];
|
||||||
|
|
||||||
for (let i = 1; i < txIds.length; i++) {
|
for (let i = 0; i < txIds.length; i++) {
|
||||||
if (mempool[txIds[i]]) {
|
if (mempool[txIds[i]]) {
|
||||||
transactions.push(mempool[txIds[i]]);
|
transactions.push(mempool[txIds[i]]);
|
||||||
found++;
|
found++;
|
||||||
|
@ -71,6 +71,7 @@ class Blocks {
|
||||||
|
|
||||||
console.log(`${found} of ${txIds.length} found in mempool. ${notFound} not found.`);
|
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);
|
transactions.sort((a, b) => b.feePerVsize - a.feePerVsize);
|
||||||
block.medianFee = transactions.length ? this.median(transactions.map((tx) => tx.feePerVsize)) : 0;
|
block.medianFee = transactions.length ? this.median(transactions.map((tx) => tx.feePerVsize)) : 0;
|
||||||
block.feeRange = transactions.length ? this.getFeesInRange(transactions, 8) : [0, 0];
|
block.feeRange = transactions.length ? this.getFeesInRange(transactions, 8) : [0, 0];
|
||||||
|
|
|
@ -87,6 +87,7 @@ export interface Block {
|
||||||
|
|
||||||
medianFee?: number;
|
medianFee?: number;
|
||||||
feeRange?: number[];
|
feeRange?: number[];
|
||||||
|
reward?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Address {
|
export interface Address {
|
||||||
|
|
|
@ -47,14 +47,28 @@
|
||||||
<td>Previous Block</td>
|
<td>Previous Block</td>
|
||||||
<td><a [routerLink]="['/block/', block.previousblockhash]" [state]="{ data: { blockHeight: blockHeight - 1 } }" title="{{ block.previousblockhash }}">{{ block.previousblockhash | shortenString : 32 }}</a></td>
|
<td><a [routerLink]="['/block/', block.previousblockhash]" [state]="{ data: { blockHeight: blockHeight - 1 } }" title="{{ block.previousblockhash }}">{{ block.previousblockhash | shortenString : 32 }}</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<ng-template [ngIf]="fees" [ngIfElse]="loadingFees">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Block subsidy</td>
|
<td>Total fees</td>
|
||||||
<td>{{ blockSubsidy | number: '1.2-2' }} BTC (<app-fiat [value]="blockSubsidy"></app-fiat>)</td>
|
<td>{{ fees | number: '1.2-8' }} BTC (<app-fiat [value]="fees * 100000000"></app-fiat>)</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Status</td>
|
<td>Reward + fees:</td>
|
||||||
<td><ng-template [ngIf]="latestBlock">{{ (latestBlock.height - block.height + 1) }} confirmation{{ (latestBlock.height - block.height + 1) === 1 ? '' : 's' }}</ng-template></td>
|
<td>
|
||||||
|
{{ blockSubsidy + fees | number: '1.2-8' }} BTC (<app-fiat [value]="(blockSubsidy + fees) * 100000000"></app-fiat>)
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
</ng-template>
|
||||||
|
<ng-template #loadingFees>
|
||||||
|
<tr>
|
||||||
|
<td>Total fees</td>
|
||||||
|
<td><span class="skeleton-loader"></span></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Reward + fees:</td>
|
||||||
|
<td><span class="skeleton-loader"></span></td>
|
||||||
|
</tr>
|
||||||
|
</ng-template>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
import { ActivatedRoute, ParamMap } from '@angular/router';
|
||||||
import { ElectrsApiService } from '../../services/electrs-api.service';
|
import { ElectrsApiService } from '../../services/electrs-api.service';
|
||||||
import { switchMap } from 'rxjs/operators';
|
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 { of } from 'rxjs';
|
||||||
import { StateService } from '../../services/state.service';
|
import { StateService } from '../../services/state.service';
|
||||||
import { WebsocketService } from 'src/app/services/websocket.service';
|
import { WebsocketService } from 'src/app/services/websocket.service';
|
||||||
|
@ -21,7 +21,8 @@ export class BlockComponent implements OnInit {
|
||||||
transactions: Transaction[];
|
transactions: Transaction[];
|
||||||
isLoadingTransactions = true;
|
isLoadingTransactions = true;
|
||||||
error: any;
|
error: any;
|
||||||
blockSubsidy = 50;
|
blockSubsidy: number;
|
||||||
|
fees: number;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
@ -37,6 +38,7 @@ export class BlockComponent implements OnInit {
|
||||||
switchMap((params: ParamMap) => {
|
switchMap((params: ParamMap) => {
|
||||||
const blockHash: string = params.get('id') || '';
|
const blockHash: string = params.get('id') || '';
|
||||||
this.error = undefined;
|
this.error = undefined;
|
||||||
|
this.fees = undefined;
|
||||||
|
|
||||||
if (history.state.data && history.state.data.blockHeight) {
|
if (history.state.data && history.state.data.blockHeight) {
|
||||||
this.blockHeight = history.state.data.blockHeight;
|
this.blockHeight = history.state.data.blockHeight;
|
||||||
|
@ -59,6 +61,9 @@ export class BlockComponent implements OnInit {
|
||||||
this.blockHeight = block.height;
|
this.blockHeight = block.height;
|
||||||
this.isLoadingBlock = false;
|
this.isLoadingBlock = false;
|
||||||
this.setBlockSubsidy();
|
this.setBlockSubsidy();
|
||||||
|
if (block.reward) {
|
||||||
|
this.fees = block.reward / 100000000;
|
||||||
|
}
|
||||||
this.getBlockTransactions(block.id);
|
this.getBlockTransactions(block.id);
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
@ -71,6 +76,7 @@ export class BlockComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
setBlockSubsidy() {
|
setBlockSubsidy() {
|
||||||
|
this.blockSubsidy = 50;
|
||||||
let halvenings = Math.floor(this.block.height / 210000);
|
let halvenings = Math.floor(this.block.height / 210000);
|
||||||
while (halvenings > 0) {
|
while (halvenings > 0) {
|
||||||
this.blockSubsidy = this.blockSubsidy / 2;
|
this.blockSubsidy = this.blockSubsidy / 2;
|
||||||
|
@ -83,6 +89,9 @@ export class BlockComponent implements OnInit {
|
||||||
this.transactions = null;
|
this.transactions = null;
|
||||||
this.electrsApiService.getBlockTransactions$(hash)
|
this.electrsApiService.getBlockTransactions$(hash)
|
||||||
.subscribe((transactions: any) => {
|
.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.transactions = transactions;
|
||||||
this.isLoadingTransactions = false;
|
this.isLoadingTransactions = false;
|
||||||
});
|
});
|
||||||
|
|
|
@ -67,6 +67,7 @@ export interface Block {
|
||||||
|
|
||||||
medianFee?: number;
|
medianFee?: number;
|
||||||
feeRange?: number[];
|
feeRange?: number[];
|
||||||
|
reward?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Address {
|
export interface Address {
|
||||||
|
|
Loading…
Add table
Reference in a new issue