From 62432f0326ab42c0804e518c1bb28aa4b311f634 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Wed, 16 Oct 2024 21:37:11 +0200 Subject: [PATCH] Add aux pow implementation --- .../core/services/daemon/daemon.service.ts | 2 +- src/app/pages/mining/mining.component.html | 66 +++++++++++++++++ src/app/pages/mining/mining.component.ts | 71 +++++++++++++++++-- .../transactions/transactions.component.html | 2 +- 4 files changed, 132 insertions(+), 9 deletions(-) diff --git a/src/app/core/services/daemon/daemon.service.ts b/src/app/core/services/daemon/daemon.service.ts index 9dd249c..fd61c46 100644 --- a/src/app/core/services/daemon/daemon.service.ts +++ b/src/app/core/services/daemon/daemon.service.ts @@ -818,7 +818,7 @@ export class DaemonService { return MinerData.parse(response.result); } - public async AddAuxPoW(blockTemplateBlob: string, auxPoW: AuxPoW[]): Promise { + public async addAuxPoW(blockTemplateBlob: string, auxPoW: AuxPoW[]): Promise { const response = await this.callRpc(new AddAuxPoWRequest(blockTemplateBlob, auxPoW)); return AddedAuxPow.parse(response.result); diff --git a/src/app/pages/mining/mining.component.html b/src/app/pages/mining/mining.component.html index 66dfda7..32610f6 100644 --- a/src/app/pages/mining/mining.component.html +++ b/src/app/pages/mining/mining.component.html @@ -283,6 +283,7 @@ {{ addAuxPowError }} + + +
+
+

Result

+
+
+ + +
+
+
Block Template Blob
+

{{ addAuxPowResult.blockTemplateBlob }}

+
+
+ + +
+
+ +
+
+
    +
  • Block Hashing Blob: {{ addAuxPowResult.blockHashingBlob }} bytes
  • +
  • Merkle Root: {{ addAuxPowResult.merkleRoot }} units
  • +
  • Merkle Three Depth: {{ addAuxPowResult.merkleTreeDepth }}
  • +
+
+
+
+
+ + +
+
+
Aux PoW
+
+
+ + + + + + + + +
IDHash
+ +
+
+
+
+
+
+
+ +
+ +
diff --git a/src/app/pages/mining/mining.component.ts b/src/app/pages/mining/mining.component.ts index aa30762..baf7241 100644 --- a/src/app/pages/mining/mining.component.ts +++ b/src/app/pages/mining/mining.component.ts @@ -5,7 +5,7 @@ import { MinerData } from '../../../common/MinerData'; import { NavigationEnd, Router } from '@angular/router'; import { NavbarLink } from '../../shared/components/navbar/navbar.model'; import { Chain } from '../../../common/Chain'; -import { AuxPoW, BlockTemplate, GeneratedBlocks, MiningStatus } from '../../../common'; +import { AddedAuxPow, AuxPoW, BlockTemplate, GeneratedBlocks, MiningStatus } from '../../../common'; import { DaemonDataService } from '../../core/services'; @Component({ @@ -127,10 +127,10 @@ export class MiningComponent implements AfterViewInit { public addAuxPowAuxPowJsonString: string = ''; public addAuxPowBlockTemplateBlob: string = ''; - public auxPowArray: AuxPoW[] = []; public addingAuxPow: boolean = false; public addAuxPowSuccess: boolean = false; public addAuxPowError: string = ''; + public addAuxPowResult?: AddedAuxPow; public get validStartMiningMinerAddress(): boolean { return this.startMiningMinerAddress != ''; @@ -168,16 +168,29 @@ export class MiningComponent implements AfterViewInit { this.navbarService.setLinks(this.navbarLinks); setTimeout(() => { - const $table = $('#chainsTable'); - $table.bootstrapTable({}); - $table.bootstrapTable('refreshOptions', { + const options = { classes: 'table table-bordered table-hover table-dark table-striped' - }); + }; + + const $chainsTable = $('#chainsTable'); + $chainsTable.bootstrapTable({}); + $chainsTable.bootstrapTable('refreshOptions', options); + this.refresh(); }, 500); } + public initAuxPowTable(): void { + const options = { + classes: 'table table-bordered table-hover table-dark table-striped' + }; + const $auxPowTable = $('#auxPowTable'); + $auxPowTable.bootstrapTable({}); + $auxPowTable.bootstrapTable('refreshOptions', options); + $auxPowTable.bootstrapTable('load', this.addAuxPowResult?.auxPoW); + } + private onNavigationEnd(): void { this.refresh(); } @@ -342,8 +355,52 @@ export class MiningComponent implements AfterViewInit { this.stoppingMining = false; } - public async addAuxPow(): Promise { + public get validAuxPowArray(): boolean { + try { + const auxPowArray: any[] = JSON.parse(this.addAuxPowAuxPowJsonString); + if (!Array.isArray(auxPowArray) || auxPowArray.length == 0) { + return false; + } + + auxPowArray.forEach((auxPow: any) => AuxPoW.parse(auxPow)); + + return true; + } + catch { + return false; + } + } + + public get auxPowArray(): AuxPoW[] { + if (!this.validAuxPowArray) { + return []; + } + + const _auxPowArray: any[] = JSON.parse(this.addAuxPowAuxPowJsonString); + + const auxPowArray: AuxPoW[] = []; + + _auxPowArray.forEach((auxPow: any) => auxPowArray.push(AuxPoW.parse(auxPow))); + + return auxPowArray; + } + + public async addAuxPow(): Promise { + this.addingAuxPow = true; + this.addAuxPowResult = undefined; + + try { + this.addAuxPowResult = await this.daemonService.addAuxPoW(this.addAuxPowBlockTemplateBlob, this.auxPowArray); + this.addAuxPowError = ``; + this.addAuxPowSuccess = true; + } + catch (error: any) { + this.addAuxPowSuccess = false; + this.addAuxPowError = `${error}`; + } + + this.addingAuxPow = false; } } diff --git a/src/app/pages/transactions/transactions.component.html b/src/app/pages/transactions/transactions.component.html index 35f9ab3..4b200cf 100644 --- a/src/app/pages/transactions/transactions.component.html +++ b/src/app/pages/transactions/transactions.component.html @@ -209,7 +209,7 @@ id="txPoolBacklogTable" data-toggle="txPoolBacklogTable" data-toolbar="#toolbar" - data-paged="true" + data-pagination="true" data-height="460" >