From 1c89a1a44ee9b8d8343c5424760990fefa8b7cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Strnad?= <43024885+vostrnad@users.noreply.github.com> Date: Mon, 1 Jul 2024 07:21:37 +0200 Subject: [PATCH] Fix missing bare multisig labels --- .../address-labels.component.ts | 12 ++++++++++ frontend/src/app/shared/address-utils.ts | 22 ++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/components/address-labels/address-labels.component.ts b/frontend/src/app/components/address-labels/address-labels.component.ts index 72a58bfca..dd81b9809 100644 --- a/frontend/src/app/components/address-labels/address-labels.component.ts +++ b/frontend/src/app/components/address-labels/address-labels.component.ts @@ -33,6 +33,8 @@ export class AddressLabelsComponent implements OnChanges { this.handleAddress(); } else if (this.vin) { this.handleVin(); + } else if (this.vout) { + this.handleVout(); } } @@ -61,4 +63,14 @@ export class AddressLabelsComponent implements OnChanges { } } } + + handleVout() { + const address = new AddressTypeInfo(this.network || 'mainnet', this.vout.scriptpubkey_address, this.vout.scriptpubkey_type as AddressType, undefined, this.vout); + if (address?.scripts.size) { + const script = address?.scripts.values().next().value; + if (script.template?.label) { + this.label = script.template.label; + } + } + } } diff --git a/frontend/src/app/shared/address-utils.ts b/frontend/src/app/shared/address-utils.ts index c5e1fcf3d..92646af14 100644 --- a/frontend/src/app/shared/address-utils.ts +++ b/frontend/src/app/shared/address-utils.ts @@ -1,6 +1,6 @@ import '@angular/localize/init'; import { ScriptInfo } from './script.utils'; -import { Vin } from '../interfaces/electrs.interface'; +import { Vin, Vout } from '../interfaces/electrs.interface'; import { BECH32_CHARS_LW, BASE58_CHARS, HEX_CHARS } from './regex.utils'; export type AddressType = 'fee' @@ -127,7 +127,7 @@ export class AddressTypeInfo { isMultisig?: { m: number, n: number }; tapscript?: boolean; - constructor (network: string, address: string, type?: AddressType, vin?: Vin[]) { + constructor (network: string, address: string, type?: AddressType, vin?: Vin[], vout?: Vout) { this.network = network; this.address = address; this.scripts = new Map(); @@ -137,6 +137,9 @@ export class AddressTypeInfo { this.type = detectAddressType(address, network); } this.processInputs(vin); + if (vout) { + this.processOutput(vout); + } } public clone(): AddressTypeInfo { @@ -180,8 +183,21 @@ export class AddressTypeInfo { } } } + } else if (this.type === 'multisig') { + if (vin.length) { + const v = vin[0]; + this.processScript(new ScriptInfo('scriptpubkey', v.prevout.scriptpubkey, v.prevout.scriptpubkey_asm)); + } + } + // and there's nothing more to learn from processing inputs for other types + } + + public processOutput(output: Vout): void { + if (this.type === 'multisig') { + if (!this.scripts.size) { + this.processScript(new ScriptInfo('scriptpubkey', output.scriptpubkey, output.scriptpubkey_asm)); + } } - // and there's nothing more to learn from processing inputs for non-scripthash types } private processScript(script: ScriptInfo): void {