Move our custom fields to a BlockExtension sub object of the IEsploraApi.Block interface

This commit is contained in:
nymkappa
2022-02-04 12:51:45 +09:00
parent e5b5551d79
commit a49cc9a2fa
19 changed files with 124 additions and 77 deletions

View File

@@ -74,9 +74,9 @@
<div class="col-sm">
<table class="table table-borderless table-striped">
<tbody>
<tr *ngIf="block.medianFee !== undefined">
<tr *ngIf="block?.extra?.medianFee != undefined">
<td class="td-width" i18n="block.median-fee">Median fee</td>
<td>~{{ block.medianFee | number:'1.0-0' }} <span class="symbol" i18n="shared.sat-vbyte|sat/vB">sat/vB</span> <span class="fiat"><app-fiat [value]="block.medianFee * 140" digitsInfo="1.2-2" i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom"></app-fiat></span></td>
<td>~{{ block?.extra?.medianFee | number:'1.0-0' }} <span class="symbol" i18n="shared.sat-vbyte|sat/vB">sat/vB</span> <span class="fiat"><app-fiat [value]="block?.extra?.medianFee * 140" digitsInfo="1.2-2" i18n-ngbTooltip="Transaction fee tooltip" ngbTooltip="Based on average native segwit transaction of 140 vBytes" placement="bottom"></app-fiat></span></td>
</tr>
<ng-template [ngIf]="fees !== undefined" [ngIfElse]="loadingFees">
<tr>

View File

@@ -3,12 +3,13 @@ import { Location } from '@angular/common';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { ElectrsApiService } from '../../services/electrs-api.service';
import { switchMap, tap, debounceTime, catchError, map } from 'rxjs/operators';
import { Block, Transaction, Vout } from '../../interfaces/electrs.interface';
import { Transaction, Vout } from '../../interfaces/electrs.interface';
import { Observable, of, Subscription } from 'rxjs';
import { StateService } from '../../services/state.service';
import { SeoService } from 'src/app/services/seo.service';
import { WebsocketService } from 'src/app/services/websocket.service';
import { RelativeUrlPipe } from 'src/app/shared/pipes/relative-url/relative-url.pipe';
import { BlockExtended } from 'src/app/interfaces/node-api.interface';
@Component({
selector: 'app-block',
@@ -17,13 +18,13 @@ import { RelativeUrlPipe } from 'src/app/shared/pipes/relative-url/relative-url.
})
export class BlockComponent implements OnInit, OnDestroy {
network = '';
block: Block;
block: BlockExtended;
blockHeight: number;
nextBlockHeight: number;
blockHash: string;
isLoadingBlock = true;
latestBlock: Block;
latestBlocks: Block[] = [];
latestBlock: BlockExtended;
latestBlocks: BlockExtended[] = [];
transactions: Transaction[];
isLoadingTransactions = true;
error: any;
@@ -76,7 +77,9 @@ export class BlockComponent implements OnInit, OnDestroy {
if (block.id === this.blockHash) {
this.block = block;
this.fees = block.reward / 100000000 - this.blockSubsidy;
if (block?.extra?.reward != undefined) {
this.fees = block.extra.reward / 100000000 - this.blockSubsidy;
}
}
});
@@ -108,7 +111,7 @@ export class BlockComponent implements OnInit, OnDestroy {
} else {
this.isLoadingBlock = true;
let blockInCache: Block;
let blockInCache: BlockExtended;
if (isBlockHeight) {
blockInCache = this.latestBlocks.find((block) => block.height === parseInt(blockHash, 10));
if (blockInCache) {
@@ -134,7 +137,7 @@ export class BlockComponent implements OnInit, OnDestroy {
return this.electrsApiService.getBlock$(blockHash);
}
}),
tap((block: Block) => {
tap((block: BlockExtended) => {
this.block = block;
this.blockHeight = block.height;
this.nextBlockHeight = block.height + 1;
@@ -142,12 +145,10 @@ export class BlockComponent implements OnInit, OnDestroy {
this.seoService.setTitle($localize`:@@block.component.browser-title:Block ${block.height}:BLOCK_HEIGHT:: ${block.id}:BLOCK_ID:`);
this.isLoadingBlock = false;
if (block.coinbaseTx) {
this.coinbaseTx = block.coinbaseTx;
}
this.coinbaseTx = block?.extra?.coinbaseTx;
this.setBlockSubsidy();
if (block.reward !== undefined) {
this.fees = block.reward / 100000000 - this.blockSubsidy;
if (block?.extra?.reward !== undefined) {
this.fees = block.extra.reward / 100000000 - this.blockSubsidy;
}
this.stateService.markBlock$.next({ blockHeight: this.blockHeight });
this.isLoadingTransactions = true;

View File

@@ -8,10 +8,10 @@
</div>
<div class="block-body">
<div class="fees">
~{{ block.medianFee | number:feeRounding }} <ng-container i18n="shared.sat-vbyte|sat/vB">sat/vB</ng-container>
~{{ block?.extra?.medianFee | number:feeRounding }} <ng-container i18n="shared.sat-vbyte|sat/vB">sat/vB</ng-container>
</div>
<div class="fee-span">
{{ block.feeRange[1] | number:feeRounding }} - {{ block.feeRange[block.feeRange.length - 1] | number:feeRounding }} <ng-container i18n="shared.sat-vbyte|sat/vB">sat/vB</ng-container>
{{ block?.extra?.feeRange[1] | number:feeRounding }} - {{ block?.extra?.feeRange[block?.extra?.feeRange.length - 1] | number:feeRounding }} <ng-container i18n="shared.sat-vbyte|sat/vB">sat/vB</ng-container>
</div>
<div class="block-size" [innerHTML]="'&lrm;' + (block.size | bytes: 2)"></div>
<div class="transaction-count">

View File

@@ -1,9 +1,9 @@
import { Component, OnInit, OnDestroy, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
import { Block } from 'src/app/interfaces/electrs.interface';
import { StateService } from 'src/app/services/state.service';
import { Router } from '@angular/router';
import { specialBlocks } from 'src/app/app.constants';
import { BlockExtended } from 'src/app/interfaces/node-api.interface';
@Component({
selector: 'app-blockchain-blocks',
@@ -14,8 +14,8 @@ import { specialBlocks } from 'src/app/app.constants';
export class BlockchainBlocksComponent implements OnInit, OnDestroy {
specialBlocks = specialBlocks;
network = '';
blocks: Block[] = [];
emptyBlocks: Block[] = this.mountEmptyBlocks();
blocks: BlockExtended[] = [];
emptyBlocks: BlockExtended[] = this.mountEmptyBlocks();
markHeight: number;
blocksSubscription: Subscription;
networkSubscription: Subscription;
@@ -69,8 +69,8 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy {
this.blocks.unshift(block);
this.blocks = this.blocks.slice(0, this.stateService.env.KEEP_BLOCKS_AMOUNT);
if (this.blocksFilled && !this.tabHidden) {
block.stage = block.matchRate >= 66 ? 1 : 2;
if (this.blocksFilled && !this.tabHidden && block.extra) {
block.extra.stage = block.extra.matchRate >= 66 ? 1 : 2;
}
if (txConfirmed) {
@@ -143,16 +143,16 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy {
}
}
trackByBlocksFn(index: number, item: Block) {
trackByBlocksFn(index: number, item: BlockExtended) {
return item.height;
}
getStyleForBlock(block: Block) {
getStyleForBlock(block: BlockExtended) {
const greenBackgroundHeight = 100 - (block.weight / this.stateService.env.BLOCK_WEIGHT_UNITS) * 100;
let addLeft = 0;
if (block.stage === 1) {
block.stage = 2;
if (block?.extra?.stage === 1) {
block.extra.stage = 2;
addLeft = -205;
}
@@ -167,11 +167,11 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy {
};
}
getStyleForEmptyBlock(block: Block) {
getStyleForEmptyBlock(block: BlockExtended) {
let addLeft = 0;
if (block.stage === 1) {
block.stage = 2;
if (block?.extra?.stage === 1) {
block.extra.stage = 2;
addLeft = -205;
}

View File

@@ -153,7 +153,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
this.blockSubscription = this.stateService.blocks$
.subscribe(([block]) => {
if (block.matchRate >= 66 && !this.tabHidden) {
if (block?.extra?.matchRate >= 66 && !this.tabHidden) {
this.blockIndex++;
}
});

View File

@@ -9,14 +9,14 @@ import {
delay,
map
} from 'rxjs/operators';
import { Transaction, Block } from '../../interfaces/electrs.interface';
import { Transaction } from '../../interfaces/electrs.interface';
import { of, merge, Subscription, Observable, Subject, timer, combineLatest, from } from 'rxjs';
import { StateService } from '../../services/state.service';
import { WebsocketService } from '../../services/websocket.service';
import { AudioService } from 'src/app/services/audio.service';
import { ApiService } from 'src/app/services/api.service';
import { SeoService } from 'src/app/services/seo.service';
import { CpfpInfo } from 'src/app/interfaces/node-api.interface';
import { BlockExtended, CpfpInfo } from 'src/app/interfaces/node-api.interface';
import { LiquidUnblinding } from './liquid-ublinding';
@Component({
@@ -33,7 +33,7 @@ export class TransactionComponent implements OnInit, OnDestroy {
error: any = undefined;
errorUnblinded: any = undefined;
waitingForTransaction = false;
latestBlock: Block;
latestBlock: BlockExtended;
transactionTime = -1;
subscription: Subscription;
fetchCpfpSubscription: Subscription;

View File

@@ -1,11 +1,12 @@
import { Component, OnInit, Input, ChangeDetectionStrategy, OnChanges, ChangeDetectorRef, Output, EventEmitter } from '@angular/core';
import { StateService } from '../../services/state.service';
import { Observable, forkJoin } from 'rxjs';
import { Block, Outspend, Transaction } from '../../interfaces/electrs.interface';
import { Outspend, Transaction } from '../../interfaces/electrs.interface';
import { ElectrsApiService } from '../../services/electrs-api.service';
import { environment } from 'src/environments/environment';
import { AssetsService } from 'src/app/services/assets.service';
import { map } from 'rxjs/operators';
import { BlockExtended } from 'src/app/interfaces/node-api.interface';
@Component({
selector: 'app-transactions-list',
@@ -26,7 +27,7 @@ export class TransactionsListComponent implements OnInit, OnChanges {
@Output() loadMore = new EventEmitter();
latestBlock$: Observable<Block>;
latestBlock$: Observable<BlockExtended>;
outspends: Outspend[] = [];
assetsMinimal: any;

View File

@@ -1,7 +1,8 @@
import { Component, ChangeDetectionStrategy, OnChanges, Input, OnInit, ChangeDetectorRef, OnDestroy } from '@angular/core';
import { Transaction, Block } from 'src/app/interfaces/electrs.interface';
import { Transaction } from 'src/app/interfaces/electrs.interface';
import { StateService } from 'src/app/services/state.service';
import { Subscription } from 'rxjs';
import { BlockExtended } from 'src/app/interfaces/node-api.interface';
@Component({
selector: 'app-tx-fee-rating',
@@ -18,7 +19,7 @@ export class TxFeeRatingComponent implements OnInit, OnChanges, OnDestroy {
overpaidTimes: number;
feeRating: number;
blocks: Block[] = [];
blocks: BlockExtended[] = [];
constructor(
private stateService: StateService,
@@ -28,7 +29,7 @@ export class TxFeeRatingComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() {
this.blocksSubscription = this.stateService.blocks$.subscribe(([block]) => {
this.blocks.push(block);
if (this.tx.status.confirmed && this.tx.status.block_height === block.height && block.medianFee > 0) {
if (this.tx.status.confirmed && this.tx.status.block_height === block.height && block?.extra?.medianFee > 0) {
this.calculateRatings(block);
this.cd.markForCheck();
}
@@ -42,7 +43,7 @@ export class TxFeeRatingComponent implements OnInit, OnChanges, OnDestroy {
}
const foundBlock = this.blocks.find((b) => b.height === this.tx.status.block_height);
if (foundBlock && foundBlock.medianFee > 0) {
if (foundBlock && foundBlock?.extra?.medianFee > 0) {
this.calculateRatings(foundBlock);
}
}
@@ -51,9 +52,9 @@ export class TxFeeRatingComponent implements OnInit, OnChanges, OnDestroy {
this.blocksSubscription.unsubscribe();
}
calculateRatings(block: Block) {
calculateRatings(block: BlockExtended) {
const feePervByte = this.tx.effectiveFeePerVsize || this.tx.fee / (this.tx.weight / 4);
this.medianFeeNeeded = block.medianFee;
this.medianFeeNeeded = block?.extra?.medianFee;
// Block not filled
if (block.weight < this.stateService.env.BLOCK_WEIGHT_UNITS * 0.95) {