From 76a07315f3206c66b720171f07debae7b60c3d05 Mon Sep 17 00:00:00 2001 From: ncois Date: Thu, 16 Nov 2023 18:36:49 +0100 Subject: [PATCH] Fix P2PK balance display in address page --- contributors/ncois.txt | 3 ++ .../transactions-list.component.ts | 46 +++++++++++++++---- 2 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 contributors/ncois.txt diff --git a/contributors/ncois.txt b/contributors/ncois.txt new file mode 100644 index 000000000..04a436613 --- /dev/null +++ b/contributors/ncois.txt @@ -0,0 +1,3 @@ +I hereby accept the terms of the Contributor License Agreement in the CONTRIBUTING.md file of the mempool/mempool git repository as of November 16, 2023. + +Signed: ncois diff --git a/frontend/src/app/components/transactions-list/transactions-list.component.ts b/frontend/src/app/components/transactions-list/transactions-list.component.ts index d066d3583..da9bdfe04 100644 --- a/frontend/src/app/components/transactions-list/transactions-list.component.ts +++ b/frontend/src/app/components/transactions-list/transactions-list.component.ts @@ -156,17 +156,45 @@ export class TransactionsListComponent implements OnInit, OnChanges { } if (this.address) { - const addressIn = tx.vout - .filter((v: Vout) => v.scriptpubkey_address === this.address) - .map((v: Vout) => v.value || 0) - .reduce((a: number, b: number) => a + b, 0); + const isP2PKUncompressed = this.address.length === 130; + const isP2PKCompressed = this.address.length === 66; + if (isP2PKCompressed) { + const addressIn = tx.vout + .filter((v: Vout) => v.scriptpubkey === '21' + this.address + 'ac') + .map((v: Vout) => v.value || 0) + .reduce((a: number, b: number) => a + b, 0); - const addressOut = tx.vin - .filter((v: Vin) => v.prevout && v.prevout.scriptpubkey_address === this.address) - .map((v: Vin) => v.prevout.value || 0) - .reduce((a: number, b: number) => a + b, 0); + const addressOut = tx.vin + .filter((v: Vin) => v.prevout && v.prevout.scriptpubkey === '21' + this.address + 'ac') + .map((v: Vin) => v.prevout.value || 0) + .reduce((a: number, b: number) => a + b, 0); - tx['addressValue'] = addressIn - addressOut; + tx['addressValue'] = addressIn - addressOut; + } else if (isP2PKUncompressed) { + const addressIn = tx.vout + .filter((v: Vout) => v.scriptpubkey === '41' + this.address + 'ac') + .map((v: Vout) => v.value || 0) + .reduce((a: number, b: number) => a + b, 0); + + const addressOut = tx.vin + .filter((v: Vin) => v.prevout && v.prevout.scriptpubkey === '41' + this.address + 'ac') + .map((v: Vin) => v.prevout.value || 0) + .reduce((a: number, b: number) => a + b, 0); + + tx['addressValue'] = addressIn - addressOut; + } else { + const addressIn = tx.vout + .filter((v: Vout) => v.scriptpubkey_address === this.address) + .map((v: Vout) => v.value || 0) + .reduce((a: number, b: number) => a + b, 0); + + const addressOut = tx.vin + .filter((v: Vin) => v.prevout && v.prevout.scriptpubkey_address === this.address) + .map((v: Vin) => v.prevout.value || 0) + .reduce((a: number, b: number) => a + b, 0); + + tx['addressValue'] = addressIn - addressOut; + } } this.priceService.getBlockPrice$(tx.status.block_time).pipe(