2022-07-12 16:13:41 +00:00
|
|
|
import { Component, OnDestroy, OnInit, AfterViewInit, ViewChildren, QueryList } from '@angular/core';
|
2022-07-07 19:11:42 +02:00
|
|
|
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
|
2022-07-12 16:13:41 +00:00
|
|
|
import { Observable, Subscription, combineLatest } from 'rxjs';
|
|
|
|
import { map, share, switchMap, tap, startWith } from 'rxjs/operators';
|
|
|
|
import { BlockAudit, TransactionStripped } from 'src/app/interfaces/node-api.interface';
|
|
|
|
import { ApiService } from 'src/app/services/api.service';
|
|
|
|
import { StateService } from 'src/app/services/state.service';
|
|
|
|
import { detectWebGL } from 'src/app/shared/graphs.utils';
|
|
|
|
import { RelativeUrlPipe } from 'src/app/shared/pipes/relative-url/relative-url.pipe';
|
2022-07-07 19:11:42 +02:00
|
|
|
import { BlockOverviewGraphComponent } from '../block-overview-graph/block-overview-graph.component';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-block-audit',
|
|
|
|
templateUrl: './block-audit.component.html',
|
|
|
|
styleUrls: ['./block-audit.component.scss'],
|
|
|
|
styles: [`
|
|
|
|
.loadingGraphs {
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: calc(50% - 15px);
|
|
|
|
z-index: 100;
|
|
|
|
}
|
|
|
|
`],
|
|
|
|
})
|
2022-07-12 16:13:41 +00:00
|
|
|
export class BlockAuditComponent implements OnInit, AfterViewInit, OnDestroy {
|
2022-07-07 19:11:42 +02:00
|
|
|
blockAudit: BlockAudit = undefined;
|
|
|
|
transactions: string[];
|
|
|
|
auditObservable$: Observable<BlockAudit>;
|
|
|
|
|
|
|
|
paginationMaxSize: number;
|
|
|
|
page = 1;
|
|
|
|
itemsPerPage: number;
|
|
|
|
|
|
|
|
mode: 'missing' | 'added' = 'missing';
|
|
|
|
isLoading = true;
|
|
|
|
webGlEnabled = true;
|
|
|
|
isMobile = window.innerWidth <= 767.98;
|
|
|
|
|
2022-07-12 16:13:41 +00:00
|
|
|
childChangeSubscription: Subscription;
|
|
|
|
|
|
|
|
@ViewChildren('blockGraphTemplate') blockGraphTemplate: QueryList<BlockOverviewGraphComponent>;
|
|
|
|
@ViewChildren('blockGraphMined') blockGraphMined: QueryList<BlockOverviewGraphComponent>;
|
2022-07-07 19:11:42 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
public stateService: StateService,
|
|
|
|
private router: Router,
|
|
|
|
private apiService: ApiService
|
|
|
|
) {
|
|
|
|
this.webGlEnabled = detectWebGL();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
2022-07-12 16:13:41 +00:00
|
|
|
this.childChangeSubscription.unsubscribe();
|
2022-07-07 19:11:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.paginationMaxSize = window.matchMedia('(max-width: 670px)').matches ? 3 : 5;
|
|
|
|
this.itemsPerPage = this.stateService.env.ITEMS_PER_PAGE;
|
|
|
|
|
|
|
|
this.auditObservable$ = this.route.paramMap.pipe(
|
|
|
|
switchMap((params: ParamMap) => {
|
|
|
|
const blockHash: string = params.get('id') || '';
|
|
|
|
return this.apiService.getBlockAudit$(blockHash)
|
|
|
|
.pipe(
|
|
|
|
map((response) => {
|
|
|
|
const blockAudit = response.body;
|
2022-10-19 00:23:45 +00:00
|
|
|
const inTemplate = {};
|
|
|
|
const inBlock = {};
|
|
|
|
const isAdded = {};
|
|
|
|
const isCensored = {};
|
|
|
|
const isMissing = {};
|
|
|
|
const isSelected = {};
|
|
|
|
for (const tx of blockAudit.template) {
|
|
|
|
inTemplate[tx.txid] = true;
|
|
|
|
}
|
|
|
|
for (const tx of blockAudit.transactions) {
|
|
|
|
inBlock[tx.txid] = true;
|
|
|
|
}
|
|
|
|
for (const txid of blockAudit.addedTxs) {
|
|
|
|
isAdded[txid] = true;
|
|
|
|
}
|
|
|
|
for (const txid of blockAudit.missingTxs) {
|
|
|
|
isCensored[txid] = true;
|
|
|
|
}
|
|
|
|
// set transaction statuses
|
|
|
|
for (const tx of blockAudit.template) {
|
|
|
|
if (isCensored[tx.txid]) {
|
|
|
|
tx.status = 'censored';
|
|
|
|
} else if (inBlock[tx.txid]) {
|
|
|
|
tx.status = 'found';
|
2022-07-07 19:11:42 +02:00
|
|
|
} else {
|
2022-10-19 00:23:45 +00:00
|
|
|
tx.status = 'missing';
|
|
|
|
isMissing[tx.txid] = true;
|
2022-07-07 19:11:42 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-19 00:23:45 +00:00
|
|
|
for (const [index, tx] of blockAudit.transactions.entries()) {
|
|
|
|
if (isAdded[tx.txid]) {
|
|
|
|
tx.status = 'added';
|
|
|
|
} else if (index === 0 || inTemplate[tx.txid]) {
|
|
|
|
tx.status = 'found';
|
2022-07-07 19:11:42 +02:00
|
|
|
} else {
|
2022-10-19 00:23:45 +00:00
|
|
|
tx.status = 'selected';
|
|
|
|
isSelected[tx.txid] = true;
|
2022-07-07 19:11:42 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-19 00:23:45 +00:00
|
|
|
for (const tx of blockAudit.transactions) {
|
|
|
|
inBlock[tx.txid] = true;
|
|
|
|
}
|
2022-07-07 19:11:42 +02:00
|
|
|
return blockAudit;
|
|
|
|
}),
|
|
|
|
tap((blockAudit) => {
|
2022-07-12 16:13:41 +00:00
|
|
|
this.blockAudit = blockAudit;
|
2022-07-07 19:11:42 +02:00
|
|
|
this.changeMode(this.mode);
|
|
|
|
this.isLoading = false;
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
share()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-12 16:13:41 +00:00
|
|
|
ngAfterViewInit() {
|
|
|
|
this.childChangeSubscription = combineLatest([this.blockGraphTemplate.changes.pipe(startWith(null)), this.blockGraphMined.changes.pipe(startWith(null))]).subscribe(() => {
|
|
|
|
console.log('changed!');
|
|
|
|
this.setupBlockGraphs();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
setupBlockGraphs() {
|
|
|
|
console.log('setting up block graphs')
|
|
|
|
if (this.blockAudit) {
|
|
|
|
this.blockGraphTemplate.forEach(graph => {
|
|
|
|
graph.destroy();
|
|
|
|
if (this.isMobile && this.mode === 'added') {
|
|
|
|
graph.setup(this.blockAudit.transactions);
|
|
|
|
} else {
|
|
|
|
graph.setup(this.blockAudit.template);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.blockGraphMined.forEach(graph => {
|
|
|
|
graph.destroy();
|
|
|
|
graph.setup(this.blockAudit.transactions);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-07 19:11:42 +02:00
|
|
|
onResize(event: any) {
|
2022-07-12 16:13:41 +00:00
|
|
|
const isMobile = event.target.innerWidth <= 767.98;
|
|
|
|
const changed = isMobile !== this.isMobile;
|
|
|
|
this.isMobile = isMobile;
|
2022-07-07 19:11:42 +02:00
|
|
|
this.paginationMaxSize = event.target.innerWidth < 670 ? 3 : 5;
|
2022-07-12 16:13:41 +00:00
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
this.changeMode(this.mode);
|
|
|
|
}
|
2022-07-07 19:11:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
changeMode(mode: 'missing' | 'added') {
|
|
|
|
this.router.navigate([], { fragment: mode });
|
|
|
|
this.mode = mode;
|
2022-07-12 16:13:41 +00:00
|
|
|
|
|
|
|
this.setupBlockGraphs();
|
2022-07-07 19:11:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onTxClick(event: TransactionStripped): void {
|
|
|
|
const url = new RelativeUrlPipe(this.stateService).transform(`/tx/${event.txid}`);
|
|
|
|
this.router.navigate([url]);
|
|
|
|
}
|
|
|
|
|
|
|
|
pageChange(page: number, target: HTMLElement) {
|
|
|
|
}
|
|
|
|
}
|